@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.
- package/dist/components/FolderTree.svelte +1 -1
- package/dist/components/FolderTree.svelte.d.ts +6 -2
- package/dist/components/core/Dropzone.svelte +147 -109
- package/dist/components/core/FileBrowser.svelte +128 -99
- package/dist/components/core/FileBrowser.svelte.d.ts +5 -1
- package/dist/components/core/FileUploader.svelte +80 -51
- package/dist/components/core/Header.svelte +1 -1
- package/dist/components/core/RecentFiles.svelte +23 -11
- package/dist/components/core/RecentFiles.svelte.d.ts +1 -0
- package/dist/components/core/SearchDropdown.svelte +125 -27
- package/dist/components/core/UploadPanel.svelte +2 -2
- package/dist/components/core/UploadRow.svelte +5 -5
- package/dist/components/items/FileItem.svelte +13 -3
- package/dist/components/items/FolderItem.svelte +8 -1
- package/dist/components/modals/MoveDialog.svelte +1 -1
- package/dist/components/modals/SelectedFilesModal.svelte +2 -2
- package/dist/components/modals/index.d.ts +0 -1
- package/dist/components/modals/index.js +0 -1
- package/dist/components/previews/FilePreview.svelte +198 -31
- package/dist/components/previews/FilePreview.svelte.d.ts +1 -0
- package/dist/components/previews/ImagePreview.svelte +60 -31
- package/dist/components/previews/ImagePreview.svelte.d.ts +3 -0
- package/dist/components/previews/PreviewHeaderBar.svelte +34 -26
- package/dist/components/previews/PreviewHeaderBar.svelte.d.ts +2 -0
- package/dist/components/previews/TextPreview.svelte +1 -1
- package/dist/components/previews/VideoPlayer.svelte +4 -4
- package/dist/components/ui/ControlToolbar.svelte +10 -10
- package/dist/components/ui/DragSelect.svelte +85 -67
- package/dist/components/ui/DragSelect.svelte.d.ts +1 -0
- package/dist/components/ui/DropdownMenu.svelte +5 -5
- package/dist/components/ui/FileIcon.svelte +2 -2
- package/dist/data/demoContent.json +13 -11
- package/dist/i18n/messages.d.ts +0 -1
- package/dist/i18n/messages.js +0 -1
- package/dist/stores/fileStore.d.ts +2 -2
- package/dist/stores/navigationStore.d.ts +6 -1
- package/dist/stores/navigationStore.js +40 -67
- package/dist/stores/persistentSelectStore.d.ts +1 -1
- package/dist/utils/escapeSelectionAction.d.ts +18 -0
- package/dist/utils/escapeSelectionAction.js +18 -0
- package/dist/utils/imagePreviewCache.d.ts +16 -0
- package/dist/utils/imagePreviewCache.js +78 -0
- package/dist/utils/imagePreviewVisualState.d.ts +19 -0
- package/dist/utils/imagePreviewVisualState.js +22 -0
- package/dist/utils/menuKeydownBubble.d.ts +9 -0
- package/dist/utils/menuKeydownBubble.js +11 -0
- package/dist/utils/previewNavigation.d.ts +4 -0
- package/dist/utils/previewNavigation.js +17 -0
- package/dist/utils/recentFiles.d.ts +6 -0
- package/dist/utils/recentFiles.js +21 -0
- package/dist/utils/recentFilesLimit.d.ts +8 -0
- package/dist/utils/recentFilesLimit.js +17 -0
- package/dist/utils/searchEscapeAction.d.ts +10 -0
- package/dist/utils/searchEscapeAction.js +12 -0
- package/dist/utils/searchItems.d.ts +2 -4
- package/dist/utils/searchItems.js +12 -5
- package/dist/utils/searchNavigation.d.ts +12 -0
- package/dist/utils/searchNavigation.js +42 -0
- package/dist/utils/uploadDisplayProgress.d.ts +4 -0
- package/dist/utils/uploadDisplayProgress.js +9 -0
- package/dist/utils/uploadPanelProgress.d.ts +5 -0
- package/dist/utils/uploadPanelProgress.js +17 -0
- package/package.json +1 -1
- package/dist/components/modals/SearchModal.svelte +0 -296
- package/dist/components/modals/SearchModal.svelte.d.ts +0 -27
|
@@ -42,6 +42,27 @@ function arePathsEqual(path1, path2) {
|
|
|
42
42
|
export function getStorageKey(instanceId = 'default') {
|
|
43
43
|
return `file-browser-navigation-${instanceId}`;
|
|
44
44
|
}
|
|
45
|
+
/** Shared localStorage id for file pickers inside the Widgetic editor (folder path only, not filter/sort). */
|
|
46
|
+
export const WIDGETIC_EDITOR_FILE_PICKER_INSTANCE_ID = 'widgetic-editor-file-picker';
|
|
47
|
+
const persistFolderPathByInstance = {};
|
|
48
|
+
/** Toggles whether this instance may write its folder path to localStorage (set from FileBrowser props). */
|
|
49
|
+
export function setPersistFolderPath(instanceId, enabled) {
|
|
50
|
+
persistFolderPathByInstance[instanceId] = enabled;
|
|
51
|
+
}
|
|
52
|
+
export function shouldPersistFolderPath(instanceId) {
|
|
53
|
+
return persistFolderPathByInstance[instanceId] === true;
|
|
54
|
+
}
|
|
55
|
+
function saveNavigationStateToStorage(instanceId, state) {
|
|
56
|
+
if (!browser || !shouldPersistFolderPath(instanceId)) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
localStorage.setItem(getStorageKey(instanceId), JSON.stringify(state));
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
console.error('Error saving navigation state:', error);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
45
66
|
function createNavigationStore(instanceId = 'default') {
|
|
46
67
|
const STORAGE_KEY = getStorageKey(instanceId);
|
|
47
68
|
// Get the initial state from storage
|
|
@@ -98,12 +119,7 @@ function createNavigationStore(instanceId = 'default') {
|
|
|
98
119
|
pathsArray: [[]],
|
|
99
120
|
currentIndex: 0
|
|
100
121
|
};
|
|
101
|
-
|
|
102
|
-
localStorage.setItem(STORAGE_KEY, JSON.stringify(rootState));
|
|
103
|
-
}
|
|
104
|
-
catch (error) {
|
|
105
|
-
console.error('Error saving navigation state:', error);
|
|
106
|
-
}
|
|
122
|
+
saveNavigationStateToStorage(instanceId, rootState);
|
|
107
123
|
return rootState;
|
|
108
124
|
}
|
|
109
125
|
return state;
|
|
@@ -183,14 +199,7 @@ function createNavigationStore(instanceId = 'default') {
|
|
|
183
199
|
pathsArray: [[]],
|
|
184
200
|
currentIndex: 0
|
|
185
201
|
};
|
|
186
|
-
|
|
187
|
-
try {
|
|
188
|
-
localStorage.setItem(STORAGE_KEY, JSON.stringify(rootState));
|
|
189
|
-
}
|
|
190
|
-
catch (error) {
|
|
191
|
-
console.error('Error saving navigation state:', error);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
202
|
+
saveNavigationStateToStorage(instanceId, rootState);
|
|
194
203
|
return rootState;
|
|
195
204
|
}
|
|
196
205
|
// Proceed with navigation
|
|
@@ -198,8 +207,6 @@ function createNavigationStore(instanceId = 'default') {
|
|
|
198
207
|
// already exists at the end of the history
|
|
199
208
|
const lastPathIndex = state.pathsArray.length - 1;
|
|
200
209
|
const lastPath = lastPathIndex >= 0 ? state.pathsArray[lastPathIndex] : null;
|
|
201
|
-
// Get the current persistHistory setting
|
|
202
|
-
const isPersistHistoryEnabled = get(persistHistory);
|
|
203
210
|
// SIMPLIFY: Always check if the path is already the last item in the history,
|
|
204
211
|
// and if so, just skip adding a duplicate regardless of other conditions
|
|
205
212
|
if (lastPath && arePathsEqual(lastPath, newPath)) {
|
|
@@ -216,14 +223,7 @@ function createNavigationStore(instanceId = 'default') {
|
|
|
216
223
|
...state,
|
|
217
224
|
currentIndex: lastPathIndex
|
|
218
225
|
};
|
|
219
|
-
|
|
220
|
-
try {
|
|
221
|
-
localStorage.setItem(STORAGE_KEY, JSON.stringify(newState));
|
|
222
|
-
}
|
|
223
|
-
catch (error) {
|
|
224
|
-
console.error('Error saving navigation state:', error);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
226
|
+
saveNavigationStateToStorage(instanceId, newState);
|
|
227
227
|
return newState;
|
|
228
228
|
}
|
|
229
229
|
// Otherwise just return the current state unchanged
|
|
@@ -245,15 +245,7 @@ function createNavigationStore(instanceId = 'default') {
|
|
|
245
245
|
...state,
|
|
246
246
|
currentIndex: existingPathIndex
|
|
247
247
|
};
|
|
248
|
-
|
|
249
|
-
try {
|
|
250
|
-
localStorage.setItem(STORAGE_KEY, JSON.stringify(newState));
|
|
251
|
-
}
|
|
252
|
-
catch (error) {
|
|
253
|
-
if (showLogs)
|
|
254
|
-
console.error('Error saving navigation state:', error);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
248
|
+
saveNavigationStateToStorage(instanceId, newState);
|
|
257
249
|
return newState;
|
|
258
250
|
}
|
|
259
251
|
// If we get here, we're adding a new unique path to the history
|
|
@@ -269,16 +261,7 @@ function createNavigationStore(instanceId = 'default') {
|
|
|
269
261
|
currentIndex: newState.currentIndex,
|
|
270
262
|
newPath: newPath.join('/')
|
|
271
263
|
});
|
|
272
|
-
|
|
273
|
-
if (browser) {
|
|
274
|
-
try {
|
|
275
|
-
localStorage.setItem(STORAGE_KEY, JSON.stringify(newState));
|
|
276
|
-
}
|
|
277
|
-
catch (error) {
|
|
278
|
-
if (showLogs)
|
|
279
|
-
console.error('Error saving navigation state:', error);
|
|
280
|
-
}
|
|
281
|
-
}
|
|
264
|
+
saveNavigationStateToStorage(instanceId, newState);
|
|
282
265
|
return newState;
|
|
283
266
|
});
|
|
284
267
|
},
|
|
@@ -289,9 +272,7 @@ function createNavigationStore(instanceId = 'default') {
|
|
|
289
272
|
...state,
|
|
290
273
|
currentIndex: state.currentIndex - 1
|
|
291
274
|
};
|
|
292
|
-
|
|
293
|
-
localStorage.setItem(STORAGE_KEY, JSON.stringify(newState));
|
|
294
|
-
}
|
|
275
|
+
saveNavigationStateToStorage(instanceId, newState);
|
|
295
276
|
return newState;
|
|
296
277
|
}
|
|
297
278
|
return state;
|
|
@@ -304,9 +285,7 @@ function createNavigationStore(instanceId = 'default') {
|
|
|
304
285
|
...state,
|
|
305
286
|
currentIndex: state.currentIndex + 1
|
|
306
287
|
};
|
|
307
|
-
|
|
308
|
-
localStorage.setItem(STORAGE_KEY, JSON.stringify(newState));
|
|
309
|
-
}
|
|
288
|
+
saveNavigationStateToStorage(instanceId, newState);
|
|
310
289
|
return newState;
|
|
311
290
|
}
|
|
312
291
|
return state;
|
|
@@ -318,8 +297,13 @@ function createNavigationStore(instanceId = 'default') {
|
|
|
318
297
|
currentIndex: 0
|
|
319
298
|
};
|
|
320
299
|
set(initialState);
|
|
321
|
-
if (browser) {
|
|
322
|
-
|
|
300
|
+
if (browser && shouldPersistFolderPath(instanceId)) {
|
|
301
|
+
try {
|
|
302
|
+
localStorage.removeItem(STORAGE_KEY);
|
|
303
|
+
}
|
|
304
|
+
catch (error) {
|
|
305
|
+
console.error('Error clearing navigation state:', error);
|
|
306
|
+
}
|
|
323
307
|
}
|
|
324
308
|
},
|
|
325
309
|
cleanupPaths: (deletedFolderId) => {
|
|
@@ -403,11 +387,9 @@ function createNavigationStore(instanceId = 'default') {
|
|
|
403
387
|
currentIndex: newCurrentIndex,
|
|
404
388
|
currentPath: newPaths[newCurrentIndex]
|
|
405
389
|
});
|
|
406
|
-
|
|
407
|
-
if (browser) {
|
|
390
|
+
saveNavigationStateToStorage(instanceId, newState);
|
|
391
|
+
if (browser && shouldPersistFolderPath(instanceId)) {
|
|
408
392
|
try {
|
|
409
|
-
localStorage.setItem(STORAGE_KEY, JSON.stringify(newState));
|
|
410
|
-
// Also clean up any other related localStorage items
|
|
411
393
|
for (const key of Object.keys(localStorage)) {
|
|
412
394
|
if (key.startsWith(`${STORAGE_KEY}-`)) {
|
|
413
395
|
localStorage.removeItem(key);
|
|
@@ -415,7 +397,7 @@ function createNavigationStore(instanceId = 'default') {
|
|
|
415
397
|
}
|
|
416
398
|
}
|
|
417
399
|
catch (error) {
|
|
418
|
-
console.error('Error
|
|
400
|
+
console.error('Error cleaning navigation-related localStorage keys:', error);
|
|
419
401
|
}
|
|
420
402
|
}
|
|
421
403
|
return newState;
|
|
@@ -482,15 +464,7 @@ function createNavigationStore(instanceId = 'default') {
|
|
|
482
464
|
currentIndex: newState.currentIndex,
|
|
483
465
|
currentPath: newState.pathsArray[newState.currentIndex]
|
|
484
466
|
});
|
|
485
|
-
|
|
486
|
-
if (browser) {
|
|
487
|
-
try {
|
|
488
|
-
localStorage.setItem(STORAGE_KEY, JSON.stringify(newState));
|
|
489
|
-
}
|
|
490
|
-
catch (error) {
|
|
491
|
-
console.error('Error saving navigation state:', error);
|
|
492
|
-
}
|
|
493
|
-
}
|
|
467
|
+
saveNavigationStateToStorage(instanceId, newState);
|
|
494
468
|
return newState;
|
|
495
469
|
});
|
|
496
470
|
}
|
|
@@ -606,8 +580,7 @@ export function getStoredState(instanceId) {
|
|
|
606
580
|
return state;
|
|
607
581
|
}
|
|
608
582
|
catch (error) {
|
|
609
|
-
|
|
610
|
-
console.error('Error reading navigation state:', error);
|
|
583
|
+
console.warn('Could not read navigation state from localStorage, using root:', error);
|
|
611
584
|
return null;
|
|
612
585
|
}
|
|
613
586
|
}
|
|
@@ -24,5 +24,5 @@ export declare const persistentSelectStore: {
|
|
|
24
24
|
update(this: void, updater: import("svelte/store").Updater<StoredSelections>): void;
|
|
25
25
|
subscribe(this: void, run: import("svelte/store").Subscriber<StoredSelections>, invalidate?: () => void): import("svelte/store").Unsubscriber;
|
|
26
26
|
};
|
|
27
|
-
export declare const validSelections: import("svelte/store").Readable<(filterType: FileFilterType, files: FileSystemItem[]) =>
|
|
27
|
+
export declare const validSelections: import("svelte/store").Readable<(filterType: FileFilterType, files: FileSystemItem[]) => FileSystemItem[]>;
|
|
28
28
|
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type EscapeSelectionAction = 'clear-selection' | 'none';
|
|
2
|
+
export interface EscapeSelectionContext {
|
|
3
|
+
key: string;
|
|
4
|
+
defaultPrevented: boolean;
|
|
5
|
+
previewOpen: boolean;
|
|
6
|
+
designSystemModalOpen: boolean;
|
|
7
|
+
inputFocused: boolean;
|
|
8
|
+
rubberBandDragActive: boolean;
|
|
9
|
+
innerEscapeHandlerOpen: boolean;
|
|
10
|
+
selectionCount: number;
|
|
11
|
+
clearableSelectionCount: number;
|
|
12
|
+
/** Editor single-file picker: Escape is handled by the host overlay, never clear here. */
|
|
13
|
+
singleFilePicker?: boolean;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Whether Escape should clear the file-browser selection (preview and inner UI keep Escape first).
|
|
17
|
+
*/
|
|
18
|
+
export declare function escapeSelectionAction(ctx: EscapeSelectionContext): EscapeSelectionAction;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether Escape should clear the file-browser selection (preview and inner UI keep Escape first).
|
|
3
|
+
*/
|
|
4
|
+
export function escapeSelectionAction(ctx) {
|
|
5
|
+
if (ctx.key !== 'Escape')
|
|
6
|
+
return 'none';
|
|
7
|
+
if (ctx.defaultPrevented)
|
|
8
|
+
return 'none';
|
|
9
|
+
if (ctx.previewOpen || ctx.designSystemModalOpen)
|
|
10
|
+
return 'none';
|
|
11
|
+
if (ctx.inputFocused || ctx.rubberBandDragActive || ctx.innerEscapeHandlerOpen)
|
|
12
|
+
return 'none';
|
|
13
|
+
if (ctx.singleFilePicker)
|
|
14
|
+
return 'none';
|
|
15
|
+
if (ctx.clearableSelectionCount <= 0)
|
|
16
|
+
return 'none';
|
|
17
|
+
return 'clear-selection';
|
|
18
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare function rememberImageNaturalSize(url: string, width: number, height: number): void;
|
|
2
|
+
export declare function getCachedImageNaturalSize(url: string): {
|
|
3
|
+
width: number;
|
|
4
|
+
height: number;
|
|
5
|
+
} | undefined;
|
|
6
|
+
/**
|
|
7
|
+
* The natural size of a picture the browser already holds decoded (shown before, in a tile or in this preview), found at once.
|
|
8
|
+
* A picture that is not in the browser's memory is not waited for: it starts loading and this returns nothing.
|
|
9
|
+
*/
|
|
10
|
+
export declare function probeDecodedImage(url: string): {
|
|
11
|
+
width: number;
|
|
12
|
+
height: number;
|
|
13
|
+
} | undefined;
|
|
14
|
+
/** Warm the decoder cache; resolves when decode finishes or the request fails. */
|
|
15
|
+
export declare function preloadImageUrl(url: string): Promise<void>;
|
|
16
|
+
export declare function clearImagePreviewCacheForTests(): void;
|
|
@@ -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
|
|
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'
|
|
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) =>
|
|
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,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;
|