@widgetic/file-browser 0.5.39 → 0.5.41

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 (65) hide show
  1. package/dist/components/FolderTree.svelte +1 -1
  2. package/dist/components/FolderTree.svelte.d.ts +6 -2
  3. package/dist/components/core/Dropzone.svelte +147 -109
  4. package/dist/components/core/FileBrowser.svelte +128 -99
  5. package/dist/components/core/FileBrowser.svelte.d.ts +5 -1
  6. package/dist/components/core/FileUploader.svelte +80 -51
  7. package/dist/components/core/Header.svelte +1 -1
  8. package/dist/components/core/RecentFiles.svelte +23 -11
  9. package/dist/components/core/RecentFiles.svelte.d.ts +1 -0
  10. package/dist/components/core/SearchDropdown.svelte +125 -27
  11. package/dist/components/core/UploadPanel.svelte +2 -2
  12. package/dist/components/core/UploadRow.svelte +5 -5
  13. package/dist/components/items/FileItem.svelte +13 -3
  14. package/dist/components/items/FolderItem.svelte +8 -1
  15. package/dist/components/modals/MoveDialog.svelte +1 -1
  16. package/dist/components/modals/SelectedFilesModal.svelte +2 -2
  17. package/dist/components/modals/index.d.ts +0 -1
  18. package/dist/components/modals/index.js +0 -1
  19. package/dist/components/previews/FilePreview.svelte +198 -31
  20. package/dist/components/previews/FilePreview.svelte.d.ts +1 -0
  21. package/dist/components/previews/ImagePreview.svelte +60 -31
  22. package/dist/components/previews/ImagePreview.svelte.d.ts +3 -0
  23. package/dist/components/previews/PreviewHeaderBar.svelte +34 -26
  24. package/dist/components/previews/PreviewHeaderBar.svelte.d.ts +2 -0
  25. package/dist/components/previews/TextPreview.svelte +1 -1
  26. package/dist/components/previews/VideoPlayer.svelte +4 -4
  27. package/dist/components/ui/ControlToolbar.svelte +10 -10
  28. package/dist/components/ui/DragSelect.svelte +85 -67
  29. package/dist/components/ui/DragSelect.svelte.d.ts +1 -0
  30. package/dist/components/ui/DropdownMenu.svelte +5 -5
  31. package/dist/components/ui/FileIcon.svelte +2 -2
  32. package/dist/data/demoContent.json +13 -11
  33. package/dist/i18n/messages.d.ts +0 -1
  34. package/dist/i18n/messages.js +0 -1
  35. package/dist/stores/fileStore.d.ts +2 -2
  36. package/dist/stores/navigationStore.d.ts +6 -1
  37. package/dist/stores/navigationStore.js +40 -67
  38. package/dist/stores/persistentSelectStore.d.ts +1 -1
  39. package/dist/utils/escapeSelectionAction.d.ts +18 -0
  40. package/dist/utils/escapeSelectionAction.js +18 -0
  41. package/dist/utils/imagePreviewCache.d.ts +16 -0
  42. package/dist/utils/imagePreviewCache.js +78 -0
  43. package/dist/utils/imagePreviewVisualState.d.ts +19 -0
  44. package/dist/utils/imagePreviewVisualState.js +22 -0
  45. package/dist/utils/menuKeydownBubble.d.ts +9 -0
  46. package/dist/utils/menuKeydownBubble.js +11 -0
  47. package/dist/utils/previewNavigation.d.ts +4 -0
  48. package/dist/utils/previewNavigation.js +17 -0
  49. package/dist/utils/recentFiles.d.ts +6 -0
  50. package/dist/utils/recentFiles.js +21 -0
  51. package/dist/utils/recentFilesLimit.d.ts +8 -0
  52. package/dist/utils/recentFilesLimit.js +17 -0
  53. package/dist/utils/searchEscapeAction.d.ts +10 -0
  54. package/dist/utils/searchEscapeAction.js +12 -0
  55. package/dist/utils/searchItems.d.ts +2 -4
  56. package/dist/utils/searchItems.js +12 -5
  57. package/dist/utils/searchNavigation.d.ts +12 -0
  58. package/dist/utils/searchNavigation.js +42 -0
  59. package/dist/utils/uploadDisplayProgress.d.ts +4 -0
  60. package/dist/utils/uploadDisplayProgress.js +9 -0
  61. package/dist/utils/uploadPanelProgress.d.ts +5 -0
  62. package/dist/utils/uploadPanelProgress.js +17 -0
  63. package/package.json +1 -1
  64. package/dist/components/modals/SearchModal.svelte +0 -296
  65. package/dist/components/modals/SearchModal.svelte.d.ts +0 -27
@@ -6,7 +6,6 @@
6
6
  const dispatch = createEventDispatcher();
7
7
 
8
8
  // Design system imports
9
- import { Portal } from '@widgetic/design-system/components';
10
9
  import Dropzone from './Dropzone.svelte';
11
10
  import UploadPanel, { type UploadPanelItem } from './UploadPanel.svelte';
12
11
  import type { UploadRowScope, UploadRowState } from './UploadRow.svelte';
@@ -40,6 +39,8 @@
40
39
  import type { ThroughputSample } from '../../utils/uploadProgressMath';
41
40
  import { overallBytesProgressRatio, ratioToPercent, UPLOAD_UI_PROGRESS_THROTTLE_MS } from '../../utils/uploadProgressMath';
42
41
  import { buildActiveRowStatusText, formatUploadPercent, type UploadPhase, updateThroughputEstimateState } from '../../utils/uploadUiHelpers';
42
+ import { monotonicDisplayProgress } from '../../utils/uploadDisplayProgress';
43
+ import { monotonicPanelProgress, nextUploadPanelPeak } from '../../utils/uploadPanelProgress';
43
44
 
44
45
  // The host's media library, when the File Browser was given one. It then stores the files, instead of the
45
46
  // Widgetic upload settings.
@@ -101,6 +102,8 @@
101
102
 
102
103
  let uploadItems: UploadItem[] = [];
103
104
  let uploadInProgress = false;
105
+ /** Highest panel bar reading this open session has shown (prevents 100→0→100 flicker). */
106
+ let uploadPanelPeakProgress = 0;
104
107
 
105
108
  // Reactive variables
106
109
  $: allowedKinds = allowedKindsOf(filter === 'all' ? allowedTypes : FILE_TYPES[filter as Exclude<FileFilterType, 'all'>]);
@@ -126,7 +129,6 @@
126
129
  includeComplete: true,
127
130
  }),
128
131
  );
129
-
130
132
  $: dropzoneState = (
131
133
  dragActive && dragInvalid
132
134
  ? 'drag-invalid'
@@ -185,7 +187,7 @@
185
187
  fileName: item.file.name,
186
188
  file: fileThumbForItem(item),
187
189
  progress: item.displayProgress,
188
- progressIndeterminate: item.uploadPhase === 'finishing',
190
+ progressIndeterminate: false,
189
191
  status: item.status,
190
192
  statusText: statusTextForItem(item),
191
193
  errorMessage: item.errorMessage,
@@ -225,9 +227,18 @@
225
227
 
226
228
  $: panelProgressTone = (failedUploadCount > 0 ? 'destructive' : 'default') as 'default' | 'destructive';
227
229
  $: panelProgressDone = completedUploadCount === totalUploadCount && failedUploadCount === 0;
228
- $: panelProgressIndeterminate =
229
- !panelProgressDone &&
230
- uploadItems.some((i) => i.status === 'uploading' && i.uploadPhase === 'finishing');
230
+ /** Finishing after 100% bytes still shows a full bar (not the empty indeterminate strip). */
231
+ $: panelProgressIndeterminate = false;
232
+ $: if (!isUploadsModalOpen) {
233
+ uploadPanelPeakProgress = 0;
234
+ } else if (overallProgress >= uploadPanelPeakProgress) {
235
+ uploadPanelPeakProgress = nextUploadPanelPeak(uploadPanelPeakProgress, overallProgress);
236
+ }
237
+ $: panelBarProgress = monotonicPanelProgress(
238
+ uploadPanelPeakProgress,
239
+ overallProgress,
240
+ panelProgressDone,
241
+ );
231
242
 
232
243
  $: panelFooterDestructive = failedUploadCount > 0;
233
244
  $: panelFooterAction =
@@ -485,10 +496,11 @@
485
496
  args.phase === 'finishing' ||
486
497
  args.rawPercent >= 100;
487
498
 
488
- const displayProgress =
489
- args.phase === 'finishing'
490
- ? 100
491
- : Math.min(100, Math.max(0, Math.round(args.rawPercent)));
499
+ const previousProgress = item.displayProgress;
500
+ const displayProgress = monotonicDisplayProgress(
501
+ previousProgress,
502
+ args.phase === 'finishing' ? 100 : args.rawPercent,
503
+ );
492
504
 
493
505
  uploadItems = uploadItems.map((it) =>
494
506
  it.id === uploadId
@@ -637,7 +649,10 @@
637
649
  if (it.id !== uploadId) return it;
638
650
  const lastTick = it.lastUiTick ?? 0;
639
651
  const shouldPaint = now - lastTick >= UPLOAD_UI_PROGRESS_THROTTLE_MS || percentage >= 100;
640
- const displayProgress = Math.min(100, Math.max(0, Math.round(percentage)));
652
+ const displayProgress = monotonicDisplayProgress(
653
+ it.displayProgress,
654
+ percentage >= 100 ? 100 : percentage,
655
+ );
641
656
  return {
642
657
  ...it,
643
658
  uploadPhase: percentage >= 100 ? 'finishing' : 'uploading',
@@ -689,10 +704,10 @@
689
704
  const lastTick = it.lastUiTick ?? 0;
690
705
  const shouldPaint =
691
706
  now - lastTick >= UPLOAD_UI_PROGRESS_THROTTLE_MS || percentage >= 100;
692
- const displayProgress = Math.min(100, Math.max(0, Math.round(percentage)));
707
+ const displayProgress = monotonicDisplayProgress(it.displayProgress, percentage);
693
708
  return {
694
709
  ...it,
695
- uploadPhase: 'uploading',
710
+ uploadPhase: percentage >= 100 ? 'finishing' : 'uploading',
696
711
  bytesUploaded: loaded,
697
712
  bytesTotal: total,
698
713
  timeRemainingSeconds: est.secondsLeft,
@@ -760,7 +775,9 @@
760
775
  lastThroughputSample: est.nextSample,
761
776
  throughputBps: est.throughputBps,
762
777
  firstThroughputSampleAt: est.firstSampleAt,
763
- ...(shouldPaint ? { displayProgress: Math.round(newPercent), lastUiTick: now } : {}),
778
+ ...(shouldPaint
779
+ ? { displayProgress: monotonicDisplayProgress(it.displayProgress, newPercent), lastUiTick: now }
780
+ : {}),
764
781
  };
765
782
  });
766
783
  }, 500);
@@ -948,6 +965,19 @@
948
965
  throw new Error('No file provided');
949
966
  }
950
967
 
968
+ let imageWidth: number | undefined;
969
+ let imageHeight: number | undefined;
970
+ if (uploadedFile.type.startsWith('image/') && typeof createImageBitmap === 'function') {
971
+ try {
972
+ const bitmap = await createImageBitmap(uploadedFile);
973
+ imageWidth = bitmap.width;
974
+ imageHeight = bitmap.height;
975
+ bitmap.close();
976
+ } catch (dimensionError) {
977
+ console.warn('[FileUploader] Could not read image dimensions for mock upload:', dimensionError);
978
+ }
979
+ }
980
+
951
981
  // Create an object URL for the file
952
982
  const objectUrl = URL.createObjectURL(uploadedFile);
953
983
 
@@ -972,6 +1002,9 @@
972
1002
  modified: new Date().toISOString(),
973
1003
  url: objectUrl,
974
1004
  thumbnail: thumbnailUrl || undefined,
1005
+ mimeType: uploadedFile.type || undefined,
1006
+ width: imageWidth,
1007
+ height: imageHeight,
975
1008
  objectUrl, // Store the object URL for cleanup
976
1009
  path,
977
1010
  folderId
@@ -1118,9 +1151,41 @@
1118
1151
  </script>
1119
1152
 
1120
1153
  <div
1121
- class="file-uploader relative w-full shrink-0"
1154
+ class="file-uploader relative flex w-full shrink-0 flex-col gap-2"
1122
1155
  bind:this={uploaderRootEl}
1123
1156
  >
1157
+ {#if isUploadsModalOpen && uploadItems.length > 0}
1158
+ <!-- Figma: upload status cards sit above the drop strip, inside the modal footer. -->
1159
+ <div class="uploads-panel-anchor flex w-full min-w-0 flex-col items-stretch">
1160
+ <UploadPanel
1161
+ items={panelItems}
1162
+ summaryScope={panelSummaryScope as UploadRowScope}
1163
+ summaryState={panelSummaryState as UploadRowState}
1164
+ summaryName={panelSummaryName}
1165
+ summaryStatus={panelSummaryStatus}
1166
+ progressValue={panelBarProgress}
1167
+ progressIndeterminate={panelProgressIndeterminate}
1168
+ progressTone={panelProgressTone}
1169
+ progressDone={panelProgressDone}
1170
+ footerText={panelFooterText}
1171
+ footerDestructive={panelFooterDestructive}
1172
+ footerAction={panelFooterAction}
1173
+ expanded={!isUploadsDrawerCollapsed}
1174
+ onToggleExpand={toggleDrawerCollapse}
1175
+ onSummaryCancel={() => {
1176
+ if (isBatchUpload) cancelActiveUploads();
1177
+ else if (uploadItems[0]) handleCancelUpload(uploadItems[0].id);
1178
+ }}
1179
+ onSummaryRetry={retryAllFailedUploads}
1180
+ onItemCancel={handleCancelUpload}
1181
+ onItemRetry={handleRetryUpload}
1182
+ onFooterAction={retryAllFailedUploads}
1183
+ showClearCompleted={completedUploadCount > 0}
1184
+ onClearCompleted={clearCompletedUploads}
1185
+ />
1186
+ </div>
1187
+ {/if}
1188
+
1124
1189
  <div class="upload-area-ct relative w-full">
1125
1190
  <input
1126
1191
  type="file"
@@ -1142,40 +1207,4 @@
1142
1207
  onBrowse={() => fileInput.click()}
1143
1208
  />
1144
1209
  </div>
1145
-
1146
- {#if isUploadsModalOpen && portalTarget && uploadItems.length > 0}
1147
- <Portal target={portalTarget}>
1148
- <div class="pointer-events-none absolute inset-0 z-[9990]">
1149
- <!-- Floats over the page just above the footer (the portal target), inset like the page -->
1150
- <div class="uploads-panel-anchor pointer-events-auto absolute bottom-full mb-4 {isCompactUploader ? 'end-4' : 'end-8'}">
1151
- <UploadPanel
1152
- items={panelItems}
1153
- summaryScope={panelSummaryScope as UploadRowScope}
1154
- summaryState={panelSummaryState as UploadRowState}
1155
- summaryName={panelSummaryName}
1156
- summaryStatus={panelSummaryStatus}
1157
- progressValue={overallProgress}
1158
- progressIndeterminate={panelProgressIndeterminate}
1159
- progressTone={panelProgressTone}
1160
- progressDone={panelProgressDone}
1161
- footerText={panelFooterText}
1162
- footerDestructive={panelFooterDestructive}
1163
- footerAction={panelFooterAction}
1164
- expanded={!isUploadsDrawerCollapsed}
1165
- onToggleExpand={toggleDrawerCollapse}
1166
- onSummaryCancel={() => {
1167
- if (isBatchUpload) cancelActiveUploads();
1168
- else if (uploadItems[0]) handleCancelUpload(uploadItems[0].id);
1169
- }}
1170
- onSummaryRetry={retryAllFailedUploads}
1171
- onItemCancel={handleCancelUpload}
1172
- onItemRetry={handleRetryUpload}
1173
- onFooterAction={retryAllFailedUploads}
1174
- showClearCompleted={completedUploadCount > 0}
1175
- onClearCompleted={clearCompletedUploads}
1176
- />
1177
- </div>
1178
- </div>
1179
- </Portal>
1180
- {/if}
1181
1210
  </div>
@@ -118,7 +118,7 @@
118
118
  handleToggleSelectedFiles();
119
119
  }}
120
120
  >
121
- <IconFiles class="size-4 stroke-[1.333]" aria-hidden="true" />
121
+ <IconFiles class="size-4 stroke-2" aria-hidden="true" />
122
122
  <Badge
123
123
  variant="default"
124
124
  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"
@@ -10,10 +10,12 @@
10
10
  import { useI18n, type Translate } from '../../i18n';
11
11
  import { dirForUserText, useTextDirection } from '@widgetic/design-system/components/textDirection';
12
12
  import { FileIcon, SelectedBadge } from '../ui';
13
+ import { persistentSelectStore } from '../../stores/persistentSelectStore';
13
14
  import { type FileFilterType } from '../../utils/fileTypes';
14
15
  import { ThumbHashImage } from '@widgetic/design-system/components';
15
16
  import { IconExclamationCircle, IconPlayerPlayFilled } from '@widgetic/design-system/icons';
16
17
  import { browser } from '$app/environment';
18
+ import { recentFilesLimitForWidth } from '../../utils/recentFilesLimit';
17
19
 
18
20
  let className = '';
19
21
  export { className as class };
@@ -24,6 +26,8 @@
24
26
  export let currentFilter: FileFilterType = 'all';
25
27
  export let allowSelecting: boolean = false;
26
28
  export let columnWidth: number = 40;
29
+ /** Cap from FileBrowser so the strip matches `getRecentFiles()`. */
30
+ export let visibleLimit: number | undefined = undefined;
27
31
 
28
32
  const { t } = useI18n();
29
33
  const textDirection = useTextDirection();
@@ -41,17 +45,19 @@
41
45
  if (windowWidth > DESKTOP_BREAKPOINT) {
42
46
  const availableWidth = windowWidth;
43
47
  gridColumns = Math.min(6, Math.floor(availableWidth / 300));
44
- maxRecentFiles = gridColumns * 2;
45
48
  } else if (windowWidth > TABLET_BREAKPOINT) {
46
49
  gridColumns = 3;
47
- maxRecentFiles = 6;
48
50
  } else {
49
51
  gridColumns = 2;
50
- maxRecentFiles = 4;
51
52
  }
53
+ maxRecentFiles = visibleLimit ?? recentFilesLimitForWidth(windowWidth);
52
54
  if (showLogs) console.log('Responsive layout updated:', { windowWidth, gridColumns, maxRecentFiles });
53
55
  }
54
56
 
57
+ $: if (visibleLimit !== undefined) {
58
+ maxRecentFiles = visibleLimit;
59
+ }
60
+
55
61
  // Figma Recent cards sit 24px apart (the tiles above them 16)
56
62
  $: gridGap = 24;
57
63
  $: numberOfColumns = gridColumns;
@@ -148,8 +154,14 @@
148
154
  }
149
155
  }
150
156
 
157
+ // Same ids as the grid: follow the persistent store so both strips stay in sync after rubber-band or tile selection.
158
+ $: selectedIdSet = new Set([
159
+ ...($persistentSelectStore[currentFilter] ?? []),
160
+ ...selectedFiles.map((selectedFile) => selectedFile.id)
161
+ ]);
162
+
151
163
  function isSelected(file: FileSystemItem): boolean {
152
- return selectedFiles.some((selectedFile) => selectedFile.id === file.id);
164
+ return selectedIdSet.has(file.id);
153
165
  }
154
166
 
155
167
  function getFormattedDate(date: string | Date, translate: Translate): string {
@@ -190,14 +202,13 @@
190
202
  }
191
203
  }
192
204
 
193
- function cardShellClass(file: FileSystemItem): string {
194
- const selected = isSelected(file);
205
+ function cardShellClass(file: FileSystemItem, selected: boolean): string {
195
206
  const interactive = !file.isMissing && !errorStates.get(file.id);
196
207
  return [
197
208
  'item-container group flex w-full flex-col gap-2 rounded-xl border bg-background p-2 transition-colors duration-fast',
198
209
  selected
199
- ? 'border-brand bg-brand-subtle ring-1 ring-inset ring-brand'
200
- : 'border-border hover:bg-accent',
210
+ ? 'border-brand bg-brand-subtle ring-1 ring-inset ring-brand data-[drag-hover=true]:bg-brand-subtle'
211
+ : 'border-border hover:bg-accent data-[drag-hover=true]:bg-accent',
201
212
  interactive ? 'cursor-pointer' : ''
202
213
  ]
203
214
  .filter(Boolean)
@@ -216,12 +227,13 @@
216
227
  style="grid-template-columns: repeat({numberOfColumns}, minmax(0, 1fr)); gap: {gridGap}px;"
217
228
  >
218
229
  {#each filteredRecentFiles as file (file.id)}
230
+ {@const fileSelected = selectedIdSet.has(file.id)}
219
231
  <!-- svelte-ignore a11y-click-events-have-key-events -->
220
232
  <!-- svelte-ignore a11y_no_static_element_interactions -->
221
233
  <div
222
234
  data-item-id={file.id}
223
- data-selected={isSelected(file) ? 'true' : undefined}
224
- class={cardShellClass(file)}
235
+ data-selected={fileSelected ? 'true' : undefined}
236
+ class={cardShellClass(file, fileSelected)}
225
237
  onclick={(e) => handleRecentCardClick(e, file)}
226
238
  >
227
239
  <button
@@ -292,7 +304,7 @@
292
304
  {getFormattedDate(file.modified || new Date(), $t)}
293
305
  </p>
294
306
  </div>
295
- {#if allowSelecting && isSelected(file)}
307
+ {#if allowSelecting && fileSelected}
296
308
  <!-- svelte-ignore a11y-click-events-have-key-events -->
297
309
  <!-- svelte-ignore a11y_no_static_element_interactions -->
298
310
  <span data-fb-recent-badge class="shrink-0" onclick={(e) => e.stopPropagation()}>
@@ -25,6 +25,7 @@ declare const RecentFiles: $$__sveltets_2_IsomorphicComponent<{
25
25
  currentFilter?: FileFilterType;
26
26
  allowSelecting?: boolean;
27
27
  columnWidth?: number;
28
+ /** Cap from FileBrowser so the strip matches `getRecentFiles()`. */ visibleLimit?: number | undefined;
28
29
  }, {
29
30
  fileClick: CustomEvent<any>;
30
31
  select: CustomEvent<any>;
@@ -10,6 +10,7 @@
10
10
  import type { FileSystemItem } from '../../types';
11
11
  import type { FileFilterType } from '../../utils/fileTypes';
12
12
  import { highlightMatchesAsHtml } from '../../utils/safeText';
13
+ import { searchEscapeAction } from '../../utils/searchEscapeAction';
13
14
  import {
14
15
  filterSearchResults,
15
16
  findItemPath,
@@ -17,6 +18,15 @@
17
18
  SEARCH_LOCATION_SEPARATOR,
18
19
  searchFileSystem
19
20
  } from '../../utils/searchItems';
21
+ import {
22
+ firstSearchIndex,
23
+ lastSearchIndex,
24
+ nextSearchIndex,
25
+ pageSearchIndex,
26
+ previousSearchIndex,
27
+ searchResultIds,
28
+ shouldResetActiveIndex
29
+ } from '../../utils/searchNavigation';
20
30
  import { useI18n } from '../../i18n';
21
31
  import { dirForUserText, useTextDirection } from '@widgetic/design-system/components/textDirection';
22
32
 
@@ -56,33 +66,67 @@
56
66
  let searchInputElement: HTMLInputElement | null = null;
57
67
 
58
68
  let searchDebounceTimer: ReturnType<typeof setTimeout> | null = null;
69
+ let debouncedResultIds = '';
70
+ let lastPointerClientX = -1;
71
+ let lastPointerClientY = -1;
72
+ let keyboardNavigationActive = false;
73
+ let keyboardNavigationClearTimer: ReturnType<typeof setTimeout> | null = null;
74
+ const searchPageStep = 10;
59
75
 
60
76
  $: debouncedTermEmpty = !searchValue.trim();
61
77
  $: showPanel = panelOpen && !debouncedTermEmpty;
62
78
 
63
- $: {
64
- const term = searchValue.trim();
79
+ function queueDebouncedSearch(term: string) {
65
80
  if (searchDebounceTimer) {
66
81
  clearTimeout(searchDebounceTimer);
67
82
  searchDebounceTimer = null;
68
83
  }
69
84
  if (!term || !root) {
70
85
  debouncedResults = [];
86
+ debouncedResultIds = '';
71
87
  activeIndex = -1;
72
- } else {
73
- searchDebounceTimer = setTimeout(() => {
74
- try {
75
- const termLower = term.toLowerCase();
76
- const raw = searchFileSystem(root, termLower, currentFilter);
77
- debouncedResults = filterSearchResults(raw, currentFilter);
78
- activeIndex = debouncedResults.length > 0 ? 0 : -1;
79
- } catch (error) {
80
- if (showLogs) console.error('[SearchDropdown] search failed:', error);
81
- debouncedResults = [];
82
- activeIndex = -1;
88
+ return;
89
+ }
90
+ 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);
83
101
  }
84
- }, 150);
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);
110
+ }
111
+
112
+ $: {
113
+ const term = searchValue.trim();
114
+ const treeRoot = root;
115
+ const filter = currentFilter;
116
+ void filter;
117
+ void treeRoot;
118
+ queueDebouncedSearch(term);
119
+ }
120
+
121
+ function markKeyboardNavigation() {
122
+ keyboardNavigationActive = true;
123
+ if (keyboardNavigationClearTimer) {
124
+ clearTimeout(keyboardNavigationClearTimer);
85
125
  }
126
+ keyboardNavigationClearTimer = setTimeout(() => {
127
+ keyboardNavigationActive = false;
128
+ keyboardNavigationClearTimer = null;
129
+ }, 400);
86
130
  }
87
131
 
88
132
  function highlightMatch(name: string, term: string): string {
@@ -105,10 +149,26 @@
105
149
  if (!resultsInner || activeIndex < 0) return;
106
150
  tick().then(() => {
107
151
  const row = resultsInner?.querySelector(`[data-result-index="${activeIndex}"]`) as HTMLElement | null;
108
- row?.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
152
+ row?.scrollIntoView({ behavior: 'auto', block: 'nearest' });
109
153
  });
110
154
  }
111
155
 
156
+ function handleResultsPointerMove(event: PointerEvent) {
157
+ if (keyboardNavigationActive) return;
158
+ const moved =
159
+ event.clientX !== lastPointerClientX || event.clientY !== lastPointerClientY;
160
+ lastPointerClientX = event.clientX;
161
+ lastPointerClientY = event.clientY;
162
+ if (!moved) return;
163
+ const target = event.target as HTMLElement | null;
164
+ const row = target?.closest('[data-result-index]') as HTMLElement | null;
165
+ if (!row) return;
166
+ const index = Number(row.dataset.resultIndex);
167
+ if (Number.isFinite(index)) {
168
+ activeIndex = index;
169
+ }
170
+ }
171
+
112
172
  function openResult(item: FileSystemItem) {
113
173
  if (!root) return;
114
174
  try {
@@ -128,6 +188,7 @@
128
188
  searchValue = '';
129
189
  panelOpen = false;
130
190
  debouncedResults = [];
191
+ debouncedResultIds = '';
131
192
  activeIndex = -1;
132
193
  // The focus leaves the field: the folder or preview that opens next owns the keyboard (Escape closes the preview)
133
194
  searchInputElement?.blur();
@@ -144,6 +205,7 @@
144
205
  function handleClear() {
145
206
  searchValue = '';
146
207
  debouncedResults = [];
208
+ debouncedResultIds = '';
147
209
  activeIndex = -1;
148
210
  panelOpen = false;
149
211
  searchInputElement?.focus();
@@ -156,11 +218,15 @@
156
218
  return;
157
219
  }
158
220
  if (e.key === 'Escape') {
221
+ // Escape closes the results, then clears the text. With nothing left to close or clear, the key is not taken
222
+ // here: it travels on, so a host that embeds the browser (the editor's picker) can close on it.
223
+ const escapeAction = searchEscapeAction({ panelOpen, searchValue });
224
+ if (escapeAction === 'pass-through') return;
159
225
  e.preventDefault();
160
226
  e.stopPropagation();
161
- if (panelOpen) {
227
+ if (escapeAction === 'close-results') {
162
228
  panelOpen = false;
163
- } else if (searchValue) {
229
+ } else {
164
230
  handleClear();
165
231
  }
166
232
  return;
@@ -170,11 +236,33 @@
170
236
  }
171
237
  if (e.key === 'ArrowDown') {
172
238
  e.preventDefault();
173
- activeIndex = (activeIndex + 1) % debouncedResults.length;
239
+ markKeyboardNavigation();
240
+ activeIndex = nextSearchIndex(activeIndex, debouncedResults.length);
174
241
  scrollActiveIntoView();
175
242
  } else if (e.key === 'ArrowUp') {
176
243
  e.preventDefault();
177
- activeIndex = activeIndex <= 0 ? debouncedResults.length - 1 : activeIndex - 1;
244
+ markKeyboardNavigation();
245
+ activeIndex = previousSearchIndex(activeIndex, debouncedResults.length);
246
+ scrollActiveIntoView();
247
+ } else if (e.key === 'Home') {
248
+ e.preventDefault();
249
+ markKeyboardNavigation();
250
+ activeIndex = firstSearchIndex(debouncedResults.length);
251
+ scrollActiveIntoView();
252
+ } else if (e.key === 'End') {
253
+ e.preventDefault();
254
+ markKeyboardNavigation();
255
+ activeIndex = lastSearchIndex(debouncedResults.length);
256
+ scrollActiveIntoView();
257
+ } else if (e.key === 'PageDown') {
258
+ e.preventDefault();
259
+ markKeyboardNavigation();
260
+ activeIndex = pageSearchIndex(activeIndex, debouncedResults.length, searchPageStep, 'down');
261
+ scrollActiveIntoView();
262
+ } else if (e.key === 'PageUp') {
263
+ e.preventDefault();
264
+ markKeyboardNavigation();
265
+ activeIndex = pageSearchIndex(activeIndex, debouncedResults.length, searchPageStep, 'up');
178
266
  scrollActiveIntoView();
179
267
  } else if (e.key === 'Enter' && activeIndex >= 0) {
180
268
  e.preventDefault();
@@ -212,6 +300,9 @@
212
300
  if (searchDebounceTimer) {
213
301
  clearTimeout(searchDebounceTimer);
214
302
  }
303
+ if (keyboardNavigationClearTimer) {
304
+ clearTimeout(keyboardNavigationClearTimer);
305
+ }
215
306
  });
216
307
 
217
308
  $: ariaActivedescendant =
@@ -258,10 +349,20 @@
258
349
  <WScrollArea
259
350
  class="search-dropdown-scroll w-full"
260
351
  style="max-height: {resultsScrollMaxHeightPx}px;"
261
- scrollOutside={true}
352
+ scrollOutside={false}
262
353
  >
263
- <div class="flex flex-col py-2" bind:this={resultsInner}>
354
+ <!-- The wrapper only hears the mouse move (to tell it from a still mouse); the listbox and the options carry the roles. -->
355
+ <!-- svelte-ignore a11y_no_static_element_interactions -->
356
+ <div
357
+ class="flex flex-col gap-0 px-2 py-2"
358
+ bind:this={resultsInner}
359
+ onpointermove={handleResultsPointerMove}
360
+ >
264
361
  {#each debouncedResults as result, index (result.id || `${result.type}-${index}`)}
362
+ <!--
363
+ The highlight is the active row only (the keys and a moving mouse set it). A hover colour of its own would
364
+ paint a second row when the mouse rests still while the keys move the highlight.
365
+ -->
265
366
  <button
266
367
  data-result-index={index}
267
368
  id={`file-browser-search-opt-${uid}-${index}`}
@@ -269,12 +370,9 @@
269
370
  role="option"
270
371
  tabindex="-1"
271
372
  aria-selected={index === activeIndex}
272
- class="search-dropdown-result flex min-h-12 w-full cursor-pointer items-center gap-3 rounded-xl py-2 ps-2 pe-3 text-start transition-colors duration-fast focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background {index === activeIndex
373
+ class="search-dropdown-result box-border flex min-h-12 w-full max-w-full cursor-pointer items-center gap-3 rounded-xl py-2 ps-2 pe-2 text-start transition-colors duration-fast focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background {index === activeIndex
273
374
  ? 'bg-accent'
274
- : 'hover:bg-accent'}"
275
- onmouseenter={() => {
276
- activeIndex = index;
277
- }}
375
+ : ''}"
278
376
  onclick={() => openResult(result)}
279
377
  >
280
378
  <FileIcon
@@ -295,7 +393,7 @@
295
393
  {#if index === activeIndex}
296
394
  <span class="hidden shrink-0 items-center gap-1 text-caption text-muted-foreground sm:flex">
297
395
  {$t('searchModal.jumpToFolder')}
298
- <IconCornerUpRight class="size-4 stroke-[1.333] rtl:rotate-180" aria-hidden="true" />
396
+ <IconCornerUpRight class="size-4 stroke-2 rtl:rotate-180" aria-hidden="true" />
299
397
  </span>
300
398
  {/if}
301
399
  </button>
@@ -71,7 +71,7 @@
71
71
  </script>
72
72
 
73
73
  <div
74
- class="upload-panel flex w-[376px] max-w-[calc(100vw-2rem)] flex-col gap-2 rounded-xl border border-border bg-background p-3 shadow-floating"
74
+ class="upload-panel flex w-full min-w-0 flex-col gap-2 rounded-xl border border-border bg-background p-3 shadow-floating"
75
75
  role="region"
76
76
  aria-label={$t('upload.panelTitle')}
77
77
  >
@@ -105,7 +105,7 @@
105
105
  onclick={onToggleExpand}
106
106
  >
107
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-[1.333] transition-transform duration-base {expanded ? '' : 'rotate-180'}" aria-hidden="true" />
108
+ <IconChevronDown class="size-4 stroke-2 transition-transform duration-base {expanded ? '' : 'rotate-180'}" aria-hidden="true" />
109
109
  </IconButton>
110
110
  {/snippet}
111
111
  </Tooltip.Trigger>
@@ -57,7 +57,7 @@
57
57
  <div class="flex h-9 w-full min-w-0 items-center gap-3">
58
58
  {#if scope === 'batch'}
59
59
  <div class="flex size-8 shrink-0 items-center justify-center rounded-lg bg-muted">
60
- <IconFiles class="size-4 stroke-[1.333] text-muted-foreground" aria-hidden="true" />
60
+ <IconFiles class="size-4 stroke-2 text-muted-foreground" aria-hidden="true" />
61
61
  </div>
62
62
  {:else if file}
63
63
  <FileIcon {file} size="sm" class="shrink-0" />
@@ -75,21 +75,21 @@
75
75
  <div class="flex shrink-0 items-center gap-1">
76
76
  {#if state === 'uploading'}
77
77
  <IconButton variant="ghost" size="default" label={$t('upload.cancel')} onclick={() => onCancel?.()}>
78
- <IconX class="size-4 stroke-[1.333]" aria-hidden="true" />
78
+ <IconX class="size-4 stroke-2" aria-hidden="true" />
79
79
  </IconButton>
80
80
  {:else if state === 'failed'}
81
81
  <IconButton variant="ghost" size="default" label={$t('upload.retry')} onclick={() => onRetry?.()}>
82
- <IconRefresh class="size-4 stroke-[1.333]" aria-hidden="true" />
82
+ <IconRefresh class="size-4 stroke-2" aria-hidden="true" />
83
83
  </IconButton>
84
84
  <IconButton variant="ghost" size="default" label={$t('upload.removeFile')} onclick={() => onCancel?.()}>
85
- <IconX class="size-4 stroke-[1.333]" aria-hidden="true" />
85
+ <IconX class="size-4 stroke-2" aria-hidden="true" />
86
86
  </IconButton>
87
87
  {:else if done}
88
88
  <span
89
89
  class="inline-flex size-8 items-center justify-center rounded-lg bg-brand-subtle text-brand"
90
90
  aria-label={$t('upload.completedAlt')}
91
91
  >
92
- <IconCheck class="size-4 stroke-[1.333]" aria-hidden="true" />
92
+ <IconCheck class="size-4 stroke-2" aria-hidden="true" />
93
93
  </span>
94
94
  {/if}
95
95
  </div>