@widgetic/file-browser 0.5.40 → 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 (51) hide show
  1. package/dist/components/core/FileBrowser.svelte +108 -55
  2. package/dist/components/core/FileBrowser.svelte.d.ts +5 -1
  3. package/dist/components/core/FileUploader.svelte +49 -15
  4. package/dist/components/core/RecentFiles.svelte +23 -11
  5. package/dist/components/core/RecentFiles.svelte.d.ts +1 -0
  6. package/dist/components/core/SearchDropdown.svelte +124 -26
  7. package/dist/components/core/UploadPanel.svelte +1 -1
  8. package/dist/components/items/FileItem.svelte +12 -2
  9. package/dist/components/items/FolderItem.svelte +8 -1
  10. package/dist/components/modals/index.d.ts +0 -1
  11. package/dist/components/modals/index.js +0 -1
  12. package/dist/components/previews/FilePreview.svelte +198 -31
  13. package/dist/components/previews/FilePreview.svelte.d.ts +1 -0
  14. package/dist/components/previews/ImagePreview.svelte +60 -31
  15. package/dist/components/previews/ImagePreview.svelte.d.ts +3 -0
  16. package/dist/components/previews/PreviewHeaderBar.svelte +33 -25
  17. package/dist/components/previews/PreviewHeaderBar.svelte.d.ts +2 -0
  18. package/dist/components/ui/DragSelect.svelte +85 -67
  19. package/dist/components/ui/DragSelect.svelte.d.ts +1 -0
  20. package/dist/data/demoContent.json +13 -11
  21. package/dist/i18n/messages.d.ts +0 -1
  22. package/dist/i18n/messages.js +0 -1
  23. package/dist/stores/navigationStore.d.ts +5 -0
  24. package/dist/stores/navigationStore.js +40 -67
  25. package/dist/utils/escapeSelectionAction.d.ts +18 -0
  26. package/dist/utils/escapeSelectionAction.js +18 -0
  27. package/dist/utils/imagePreviewCache.d.ts +16 -0
  28. package/dist/utils/imagePreviewCache.js +78 -0
  29. package/dist/utils/imagePreviewVisualState.d.ts +19 -0
  30. package/dist/utils/imagePreviewVisualState.js +22 -0
  31. package/dist/utils/menuKeydownBubble.d.ts +9 -0
  32. package/dist/utils/menuKeydownBubble.js +11 -0
  33. package/dist/utils/previewNavigation.d.ts +4 -0
  34. package/dist/utils/previewNavigation.js +17 -0
  35. package/dist/utils/recentFiles.d.ts +6 -0
  36. package/dist/utils/recentFiles.js +21 -0
  37. package/dist/utils/recentFilesLimit.d.ts +8 -0
  38. package/dist/utils/recentFilesLimit.js +17 -0
  39. package/dist/utils/searchEscapeAction.d.ts +10 -0
  40. package/dist/utils/searchEscapeAction.js +12 -0
  41. package/dist/utils/searchItems.d.ts +2 -4
  42. package/dist/utils/searchItems.js +12 -5
  43. package/dist/utils/searchNavigation.d.ts +12 -0
  44. package/dist/utils/searchNavigation.js +42 -0
  45. package/dist/utils/uploadDisplayProgress.d.ts +4 -0
  46. package/dist/utils/uploadDisplayProgress.js +9 -0
  47. package/dist/utils/uploadPanelProgress.d.ts +5 -0
  48. package/dist/utils/uploadPanelProgress.js +17 -0
  49. package/package.json +1 -1
  50. package/dist/components/modals/SearchModal.svelte +0 -296
  51. package/dist/components/modals/SearchModal.svelte.d.ts +0 -27
@@ -0,0 +1,78 @@
1
+ /** Natural pixel size of a picture the preview has already decoded, keyed by its fetch URL. */
2
+ const MAX_CACHED_URLS = 64;
3
+ const naturalSizeByUrl = new Map();
4
+ export function rememberImageNaturalSize(url, width, height) {
5
+ if (!url || !width || !height)
6
+ return;
7
+ if (naturalSizeByUrl.has(url)) {
8
+ naturalSizeByUrl.delete(url);
9
+ }
10
+ naturalSizeByUrl.set(url, { width, height });
11
+ while (naturalSizeByUrl.size > MAX_CACHED_URLS) {
12
+ const oldest = naturalSizeByUrl.keys().next().value;
13
+ if (oldest)
14
+ naturalSizeByUrl.delete(oldest);
15
+ }
16
+ }
17
+ export function getCachedImageNaturalSize(url) {
18
+ if (!url)
19
+ return undefined;
20
+ const hit = naturalSizeByUrl.get(url);
21
+ return hit ? { ...hit } : undefined;
22
+ }
23
+ /**
24
+ * The natural size of a picture the browser already holds decoded (shown before, in a tile or in this preview), found at once.
25
+ * A picture that is not in the browser's memory is not waited for: it starts loading and this returns nothing.
26
+ */
27
+ export function probeDecodedImage(url) {
28
+ const known = getCachedImageNaturalSize(url);
29
+ if (known)
30
+ return known;
31
+ if (!url || typeof Image === 'undefined')
32
+ return undefined;
33
+ const probe = new Image();
34
+ probe.src = url;
35
+ if (probe.complete && probe.naturalWidth > 0 && probe.naturalHeight > 0) {
36
+ rememberImageNaturalSize(url, probe.naturalWidth, probe.naturalHeight);
37
+ return { width: probe.naturalWidth, height: probe.naturalHeight };
38
+ }
39
+ return undefined;
40
+ }
41
+ const inFlightByUrl = new Map();
42
+ /** Warm the decoder cache; resolves when decode finishes or the request fails. */
43
+ export function preloadImageUrl(url) {
44
+ if (!url)
45
+ return Promise.resolve();
46
+ const cached = naturalSizeByUrl.get(url);
47
+ if (cached)
48
+ return Promise.resolve();
49
+ const pending = inFlightByUrl.get(url);
50
+ if (pending)
51
+ return pending;
52
+ const job = new Promise((resolve) => {
53
+ const img = new Image();
54
+ img.onload = () => {
55
+ if (img.naturalWidth && img.naturalHeight) {
56
+ rememberImageNaturalSize(url, img.naturalWidth, img.naturalHeight);
57
+ }
58
+ inFlightByUrl.delete(url);
59
+ resolve();
60
+ };
61
+ img.onerror = () => {
62
+ inFlightByUrl.delete(url);
63
+ resolve();
64
+ };
65
+ img.src = url;
66
+ if (img.complete && img.naturalWidth > 0) {
67
+ rememberImageNaturalSize(url, img.naturalWidth, img.naturalHeight);
68
+ inFlightByUrl.delete(url);
69
+ resolve();
70
+ }
71
+ });
72
+ inFlightByUrl.set(url, job);
73
+ return job;
74
+ }
75
+ export function clearImagePreviewCacheForTests() {
76
+ naturalSizeByUrl.clear();
77
+ inFlightByUrl.clear();
78
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Timing rules of the image preview (round 26, item 17).
3
+ *
4
+ * What the person sees when a picture opens in the preview card:
5
+ * - a picture the browser already holds (opened before, or loaded as a neighbour): shown at once, no spinner;
6
+ * - any other picture: the frame stays empty while it loads. Only if it is STILL not there after
7
+ * `IMAGE_SLOW_LOADER_DELAY_MS` does a spinner (no text) appear; a picture that arrives sooner never shows one;
8
+ * - when the picture has loaded, the card has had `IMAGE_FRAME_EASE_MS` to ease to the picture's size before the
9
+ * picture fades in (a picture that arrives long after the card was sized shows at once).
10
+ */
11
+ /** How long a picture may take before the spinner shows ("more than a few seconds" in the request, round 26). */
12
+ export declare const IMAGE_SLOW_LOADER_DELAY_MS = 2000;
13
+ /** The card eases to the size of its picture for this long, the picture waits for the end of that move. */
14
+ export declare const IMAGE_FRAME_EASE_MS = 220;
15
+ /**
16
+ * How much longer the picture has to wait, once it has loaded, so that it appears after the card's move.
17
+ * 0 when the card reached its size long ago; never more than the move itself (a clock that went backwards).
18
+ */
19
+ export declare function imageRevealDelayMs(frameSizedAtMs: number, nowMs: number, easeMs?: number): number;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Timing rules of the image preview (round 26, item 17).
3
+ *
4
+ * What the person sees when a picture opens in the preview card:
5
+ * - a picture the browser already holds (opened before, or loaded as a neighbour): shown at once, no spinner;
6
+ * - any other picture: the frame stays empty while it loads. Only if it is STILL not there after
7
+ * `IMAGE_SLOW_LOADER_DELAY_MS` does a spinner (no text) appear; a picture that arrives sooner never shows one;
8
+ * - when the picture has loaded, the card has had `IMAGE_FRAME_EASE_MS` to ease to the picture's size before the
9
+ * picture fades in (a picture that arrives long after the card was sized shows at once).
10
+ */
11
+ /** How long a picture may take before the spinner shows ("more than a few seconds" in the request, round 26). */
12
+ export const IMAGE_SLOW_LOADER_DELAY_MS = 2000;
13
+ /** The card eases to the size of its picture for this long, the picture waits for the end of that move. */
14
+ export const IMAGE_FRAME_EASE_MS = 220;
15
+ /**
16
+ * How much longer the picture has to wait, once it has loaded, so that it appears after the card's move.
17
+ * 0 when the card reached its size long ago; never more than the move itself (a clock that went backwards).
18
+ */
19
+ export function imageRevealDelayMs(frameSizedAtMs, nowMs, easeMs = IMAGE_FRAME_EASE_MS) {
20
+ const elapsedMs = nowMs - frameSizedAtMs;
21
+ return Math.min(easeMs, Math.max(0, easeMs - elapsedMs));
22
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Whether a key pressed on a tile's "Open menu" (three dots) button stays inside that button.
3
+ *
4
+ * Enter, Space and the arrows belong to the button and its menu, so they must not reach the tile or the file browser.
5
+ * Escape is the exception: it has to travel on to the file browser (deselect) and to the host that embeds it
6
+ * (the editor closes its picker on Escape), exactly as it does when any other part of the tile has focus.
7
+ * Without the exception, Escape did nothing once the dots button had focus (a menu closes by handing focus back to it).
8
+ */
9
+ export declare function shouldKeepKeydownInsideMenu(key: string): boolean;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Whether a key pressed on a tile's "Open menu" (three dots) button stays inside that button.
3
+ *
4
+ * Enter, Space and the arrows belong to the button and its menu, so they must not reach the tile or the file browser.
5
+ * Escape is the exception: it has to travel on to the file browser (deselect) and to the host that embeds it
6
+ * (the editor closes its picker on Escape), exactly as it does when any other part of the tile has focus.
7
+ * Without the exception, Escape did nothing once the dots button had focus (a menu closes by handing focus back to it).
8
+ */
9
+ export function shouldKeepKeydownInsideMenu(key) {
10
+ return key !== 'Escape';
11
+ }
@@ -0,0 +1,4 @@
1
+ import type { FileSystemItem } from '../types';
2
+ /** Whether two files should be reachable via preview chevrons (same preview surface). */
3
+ export declare function isSamePreviewLane(file: FileSystemItem, candidate: FileSystemItem): boolean;
4
+ export declare function countPreviewNavigationPeers(files: FileSystemItem[], current: FileSystemItem, missingIds?: ReadonlySet<string>): number;
@@ -0,0 +1,17 @@
1
+ import { getFileTypeOf } from './fileKinds';
2
+ /** Whether two files should be reachable via preview chevrons (same preview surface). */
3
+ export function isSamePreviewLane(file, candidate) {
4
+ if (candidate.type !== 'file')
5
+ return false;
6
+ const kind = getFileTypeOf(file);
7
+ const other = getFileTypeOf(candidate);
8
+ if (kind === 'image' || kind === 'svg')
9
+ return other === 'image' || other === 'svg';
10
+ return other === kind;
11
+ }
12
+ export function countPreviewNavigationPeers(files, current, missingIds = new Set()) {
13
+ return files.filter((item) => item.type === 'file' &&
14
+ item.id !== current.id &&
15
+ !missingIds.has(item.id) &&
16
+ isSamePreviewLane(current, item)).length;
17
+ }
@@ -0,0 +1,6 @@
1
+ import type { FileSystemItem } from '../types';
2
+ export type RecentFilesSortKey = 'modified';
3
+ /**
4
+ * Stable recent-files list: newest first, one row per resolved picture URL (fallback: file id).
5
+ */
6
+ export declare function buildDeduplicatedRecentFiles(files: FileSystemItem[], resolveUrl: (file: FileSystemItem) => string, limit: number): FileSystemItem[];
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Stable recent-files list: newest first, one row per resolved picture URL (fallback: file id).
3
+ */
4
+ export function buildDeduplicatedRecentFiles(files, resolveUrl, limit) {
5
+ if (limit <= 0 || files.length === 0)
6
+ return [];
7
+ const sorted = [...files].sort((a, b) => new Date(b.modified || 0).getTime() - new Date(a.modified || 0).getTime());
8
+ const seen = new Set();
9
+ const result = [];
10
+ for (const file of sorted) {
11
+ const urlKey = file.url ? resolveUrl(file) : file.id;
12
+ const dedupeKey = urlKey || file.id;
13
+ if (seen.has(dedupeKey))
14
+ continue;
15
+ seen.add(dedupeKey);
16
+ result.push(file);
17
+ if (result.length >= limit)
18
+ break;
19
+ }
20
+ return result;
21
+ }
@@ -0,0 +1,8 @@
1
+ /** Breakpoints shared by the main grid and the Recent strip (Figma desktop / tablet). */
2
+ export declare const RECENT_FILES_DESKTOP_BREAKPOINT = 1156;
3
+ export declare const RECENT_FILES_TABLET_BREAKPOINT = 744;
4
+ /**
5
+ * How many recent file cards to prepare and show for a container width.
6
+ * One rule for FileBrowser and RecentFiles so the strip matches `getRecentFiles()`.
7
+ */
8
+ export declare function recentFilesLimitForWidth(containerWidth: number): number;
@@ -0,0 +1,17 @@
1
+ /** Breakpoints shared by the main grid and the Recent strip (Figma desktop / tablet). */
2
+ export const RECENT_FILES_DESKTOP_BREAKPOINT = 1156;
3
+ export const RECENT_FILES_TABLET_BREAKPOINT = 744;
4
+ /**
5
+ * How many recent file cards to prepare and show for a container width.
6
+ * One rule for FileBrowser and RecentFiles so the strip matches `getRecentFiles()`.
7
+ */
8
+ export function recentFilesLimitForWidth(containerWidth) {
9
+ if (containerWidth > RECENT_FILES_DESKTOP_BREAKPOINT) {
10
+ const gridColumns = Math.min(6, Math.floor(containerWidth / 300));
11
+ return gridColumns * 2;
12
+ }
13
+ if (containerWidth > RECENT_FILES_TABLET_BREAKPOINT) {
14
+ return 6;
15
+ }
16
+ return 4;
17
+ }
@@ -0,0 +1,10 @@
1
+ export type SearchEscapeAction = 'close-results' | 'clear-text' | 'pass-through';
2
+ /**
3
+ * What Escape does in the search field: it closes the results first, then clears the text. With nothing left to close
4
+ * or clear the key is not taken by the field and travels on, so a host that embeds the File Browser (the editor's
5
+ * picker) can close on it, as it does for any other modal.
6
+ */
7
+ export declare function searchEscapeAction(state: {
8
+ panelOpen: boolean;
9
+ searchValue: string;
10
+ }): SearchEscapeAction;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * What Escape does in the search field: it closes the results first, then clears the text. With nothing left to close
3
+ * or clear the key is not taken by the field and travels on, so a host that embeds the File Browser (the editor's
4
+ * picker) can close on it, as it does for any other modal.
5
+ */
6
+ export function searchEscapeAction(state) {
7
+ if (state.panelOpen)
8
+ return 'close-results';
9
+ if (state.searchValue)
10
+ return 'clear-text';
11
+ return 'pass-through';
12
+ }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Global file-tree search helpers shared by SearchModal and SearchDropdown.
2
+ * Global file-tree search helpers shared by SearchDropdown.
3
3
  */
4
4
  import type { FileSystemItem } from '../types';
5
5
  import type { FileFilterType } from './fileTypes';
@@ -21,7 +21,5 @@ export declare const SEARCH_LOCATION_SEPARATOR = " / ";
21
21
  * `idPath` is from {@link findItemPath} for the result item.
22
22
  */
23
23
  export declare function parentFolderLocationLabel(root: FileSystemItem, idPath: string[], rootDisplayLabel: string, listSeparator: string): string;
24
- /**
25
- * Applies the same post-search filter as the legacy modal: drop `Root`, keep folders always, files must match filter.
26
- */
24
+ /** Drops `Root` if it slipped in; folders stay visible even when empty. */
27
25
  export declare function filterSearchResults(items: FileSystemItem[], currentFilter: FileFilterType): FileSystemItem[];
@@ -15,7 +15,10 @@ export function matchesFileFilter(item, currentFilter) {
15
15
  export function searchFileSystem(item, termLower, currentFilter) {
16
16
  let results = [];
17
17
  if (item.name.toLowerCase().includes(termLower) && item.name !== 'Root') {
18
- if (item.type === 'folder' || matchesFileFilter(item, currentFilter)) {
18
+ if (item.type === 'folder') {
19
+ results.push(item);
20
+ }
21
+ else if (matchesFileFilter(item, currentFilter)) {
19
22
  results.push(item);
20
23
  }
21
24
  }
@@ -69,9 +72,13 @@ export function parentFolderLocationLabel(root, idPath, rootDisplayLabel, listSe
69
72
  }
70
73
  return parts.join(listSeparator);
71
74
  }
72
- /**
73
- * Applies the same post-search filter as the legacy modal: drop `Root`, keep folders always, files must match filter.
74
- */
75
+ /** Drops `Root` if it slipped in; folders stay visible even when empty. */
75
76
  export function filterSearchResults(items, currentFilter) {
76
- return items.filter((item) => item.name !== 'Root' && (item.type === 'folder' || matchesFileFilter(item, currentFilter)));
77
+ return items.filter((item) => {
78
+ if (item.name === 'Root')
79
+ return false;
80
+ if (item.type === 'folder')
81
+ return true;
82
+ return matchesFileFilter(item, currentFilter);
83
+ });
77
84
  }
@@ -0,0 +1,12 @@
1
+ /** Pure helpers for search result list keyboard / reset behavior (SearchDropdown). */
2
+ export declare function searchResultIds(items: ReadonlyArray<{
3
+ id?: string;
4
+ type?: string;
5
+ }>): string;
6
+ /** True when the active row should reset to the first result (new result set). */
7
+ export declare function shouldResetActiveIndex(previousIds: string, nextIds: string): boolean;
8
+ export declare function nextSearchIndex(currentIndex: number, resultCount: number): number;
9
+ export declare function previousSearchIndex(currentIndex: number, resultCount: number): number;
10
+ export declare function firstSearchIndex(resultCount: number): number;
11
+ export declare function lastSearchIndex(resultCount: number): number;
12
+ export declare function pageSearchIndex(currentIndex: number, resultCount: number, pageSize: number, direction: 'down' | 'up'): number;
@@ -0,0 +1,42 @@
1
+ /** Pure helpers for search result list keyboard / reset behavior (SearchDropdown). */
2
+ export function searchResultIds(items) {
3
+ return items
4
+ .map((item, index) => item.id ?? `${item.type ?? 'item'}-${index}`)
5
+ .join('\0');
6
+ }
7
+ /** True when the active row should reset to the first result (new result set). */
8
+ export function shouldResetActiveIndex(previousIds, nextIds) {
9
+ return previousIds !== nextIds;
10
+ }
11
+ export function nextSearchIndex(currentIndex, resultCount) {
12
+ if (resultCount <= 0)
13
+ return -1;
14
+ if (currentIndex < 0)
15
+ return 0;
16
+ return (currentIndex + 1) % resultCount;
17
+ }
18
+ export function previousSearchIndex(currentIndex, resultCount) {
19
+ if (resultCount <= 0)
20
+ return -1;
21
+ if (currentIndex <= 0)
22
+ return resultCount - 1;
23
+ return currentIndex - 1;
24
+ }
25
+ export function firstSearchIndex(resultCount) {
26
+ return resultCount > 0 ? 0 : -1;
27
+ }
28
+ export function lastSearchIndex(resultCount) {
29
+ return resultCount > 0 ? resultCount - 1 : -1;
30
+ }
31
+ export function pageSearchIndex(currentIndex, resultCount, pageSize, direction) {
32
+ if (resultCount <= 0)
33
+ return -1;
34
+ const safePage = Math.max(1, pageSize);
35
+ const base = currentIndex < 0 ? 0 : currentIndex;
36
+ if (direction === 'down') {
37
+ const next = base + safePage;
38
+ return next >= resultCount ? resultCount - 1 : next;
39
+ }
40
+ const previous = base - safePage;
41
+ return previous < 0 ? 0 : previous;
42
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Keeps upload row / panel progress values from moving backward (e.g. 100 → 0 when switching to indeterminate).
3
+ */
4
+ export declare function monotonicDisplayProgress(previous: number | undefined, next: number): number;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Keeps upload row / panel progress values from moving backward (e.g. 100 → 0 when switching to indeterminate).
3
+ */
4
+ export function monotonicDisplayProgress(previous, next) {
5
+ const clamped = Math.min(100, Math.max(0, Math.round(next)));
6
+ if (previous === undefined || !Number.isFinite(previous))
7
+ return clamped;
8
+ return Math.max(previous, clamped);
9
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Panel-level upload bar must never visually regress (CSS width transitions amplify brief dips).
3
+ */
4
+ export declare function monotonicPanelProgress(previousPeak: number, nextOverall: number, allSuccess: boolean): number;
5
+ export declare function nextUploadPanelPeak(previousPeak: number, displayProgress: number): number;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Panel-level upload bar must never visually regress (CSS width transitions amplify brief dips).
3
+ */
4
+ export function monotonicPanelProgress(previousPeak, nextOverall, allSuccess) {
5
+ const safeNext = Number.isFinite(nextOverall) ? Math.min(100, Math.max(0, nextOverall)) : 0;
6
+ const safePeak = Number.isFinite(previousPeak) ? Math.min(100, Math.max(0, previousPeak)) : 0;
7
+ if (allSuccess)
8
+ return 100;
9
+ return Math.max(safePeak, safeNext);
10
+ }
11
+ export function nextUploadPanelPeak(previousPeak, displayProgress) {
12
+ const safeDisplay = Number.isFinite(displayProgress)
13
+ ? Math.min(100, Math.max(0, displayProgress))
14
+ : 0;
15
+ const safePeak = Number.isFinite(previousPeak) ? Math.min(100, Math.max(0, previousPeak)) : 0;
16
+ return Math.max(safePeak, safeDisplay);
17
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@widgetic/file-browser",
3
- "version": "0.5.40",
3
+ "version": "0.5.41",
4
4
  "license": "SEE LICENSE IN LICENSE",
5
5
  "type": "module",
6
6
  "repository": {