@widgetic/file-browser 0.5.45 → 0.5.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/FolderTree.svelte.d.ts +2 -1
- package/dist/components/core/Dropzone.svelte +15 -28
- package/dist/components/core/FileBrowser.svelte +86 -110
- package/dist/components/core/Header.svelte +30 -39
- package/dist/components/core/RecentFiles.svelte +7 -37
- package/dist/components/core/RecentFiles.svelte.d.ts +1 -0
- package/dist/components/core/SearchDropdown.svelte +88 -26
- package/dist/components/core/SearchDropdown.svelte.d.ts +2 -0
- package/dist/components/core/UploadPanel.svelte +19 -24
- package/dist/components/previews/FilePreview.svelte +26 -50
- package/dist/components/previews/PreviewHeaderBar.svelte +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/stores/fileStore.d.ts +2 -2
- package/dist/types.d.ts +2 -0
- package/dist/utils/brandKitLibraryTree.d.ts +23 -0
- package/dist/utils/brandKitLibraryTree.js +135 -0
- package/dist/utils/gridLayout.d.ts +14 -1
- package/dist/utils/gridLayout.js +27 -2
- package/dist/utils/libraryTree.js +13 -2
- package/dist/utils/previewListNavigation.d.ts +10 -0
- package/dist/utils/previewListNavigation.js +39 -0
- package/dist/utils/recentFilesLimit.js +2 -5
- package/dist/utils/searchDropdownPhase.d.ts +17 -0
- package/dist/utils/searchDropdownPhase.js +23 -0
- package/dist/utils/widgeticUpload.js +2 -0
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Pure helpers for the Widgetic library-mode tree: persistence covers the whole root and API hydration merges by id.
|
|
3
3
|
*/
|
|
4
|
+
import { placeBrandKitFileInTree } from './brandKitLibraryTree.js';
|
|
4
5
|
export const BUILTIN_UPLOADS_ID = 'folder_my_uploads';
|
|
5
6
|
function sortFolderContentsLikeGrid(items, sort) {
|
|
6
7
|
items.sort((a, b) => {
|
|
@@ -98,8 +99,9 @@ export function mergeApiFilesIntoSavedTree(rootChildren, apiFiles, _myUploadsNam
|
|
|
98
99
|
for (let i = 0; i < items.length; i++) {
|
|
99
100
|
const it = items[i];
|
|
100
101
|
if (it.type === 'file' && it.id === id) {
|
|
101
|
-
//
|
|
102
|
-
|
|
102
|
+
// Brand-kit uploads keep the server file name; other files keep a visitor rename.
|
|
103
|
+
const name = file.libraryFolderPath ? file.name : it.name;
|
|
104
|
+
items[i] = { ...file, name, modified: ensureDate(file.modified) };
|
|
103
105
|
return true;
|
|
104
106
|
}
|
|
105
107
|
if (it.type === 'folder' && it.children?.length) {
|
|
@@ -125,6 +127,15 @@ export function mergeApiFilesIntoSavedTree(rootChildren, apiFiles, _myUploadsNam
|
|
|
125
127
|
if (findItemByIdInTree(rootFolder, file.id)) {
|
|
126
128
|
replaceFileById(rootFolder.children, file.id, normalized);
|
|
127
129
|
}
|
|
130
|
+
else if (file.libraryFolderPath) {
|
|
131
|
+
const placed = placeBrandKitFileInTree(rootFolder.children, {
|
|
132
|
+
uploadId: file.id,
|
|
133
|
+
displayName: file.name,
|
|
134
|
+
folderPath: file.libraryFolderPath.split('/').filter(Boolean),
|
|
135
|
+
file: normalized
|
|
136
|
+
});
|
|
137
|
+
rootFolder.children = placed;
|
|
138
|
+
}
|
|
128
139
|
else if (!rootFolder.children.some((c) => c.type === 'file' && c.id === file.id)) {
|
|
129
140
|
rootFolder.children.push(normalized);
|
|
130
141
|
sortFolderContentsLikeGrid(rootFolder.children, {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { FileSystemItem } from '../types';
|
|
2
|
+
/** Previewable items in display order (folders omitted). */
|
|
3
|
+
export declare function previewNavigationFiles(items: FileSystemItem[]): FileSystemItem[];
|
|
4
|
+
export declare function previewNavigationIndex(list: FileSystemItem[], fileId: string): number;
|
|
5
|
+
/**
|
|
6
|
+
* Next file in the preview list, wrapping at both ends. Skips missing ids when provided.
|
|
7
|
+
* Returns null when there is no navigable file (empty list or every peer missing).
|
|
8
|
+
*/
|
|
9
|
+
export declare function stepPreviewNavigation(list: FileSystemItem[], currentId: string, direction: 'next' | 'prev', missingIds?: ReadonlySet<string>): FileSystemItem | null;
|
|
10
|
+
export declare function hasPreviewNavigation(list: FileSystemItem[], missingIds?: ReadonlySet<string>): boolean;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** Previewable items in display order (folders omitted). */
|
|
2
|
+
export function previewNavigationFiles(items) {
|
|
3
|
+
return items.filter((item) => item.type === 'file');
|
|
4
|
+
}
|
|
5
|
+
export function previewNavigationIndex(list, fileId) {
|
|
6
|
+
return list.findIndex((item) => item.id === fileId);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Next file in the preview list, wrapping at both ends. Skips missing ids when provided.
|
|
10
|
+
* Returns null when there is no navigable file (empty list or every peer missing).
|
|
11
|
+
*/
|
|
12
|
+
export function stepPreviewNavigation(list, currentId, direction, missingIds = new Set()) {
|
|
13
|
+
const files = previewNavigationFiles(list);
|
|
14
|
+
if (files.length <= 1)
|
|
15
|
+
return null;
|
|
16
|
+
let index = previewNavigationIndex(files, currentId);
|
|
17
|
+
if (index < 0)
|
|
18
|
+
index = 0;
|
|
19
|
+
const total = files.length;
|
|
20
|
+
for (let step = 0; step < total; step++) {
|
|
21
|
+
if (direction === 'next') {
|
|
22
|
+
index = (index + 1) % total;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
index = index > 0 ? index - 1 : total - 1;
|
|
26
|
+
}
|
|
27
|
+
const candidate = files[index];
|
|
28
|
+
if (candidate.id !== currentId && !missingIds.has(candidate.id)) {
|
|
29
|
+
return candidate;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
// Wrapped full cycle with only the current file available
|
|
33
|
+
const current = files.find((f) => f.id === currentId);
|
|
34
|
+
return current && !missingIds.has(current.id) ? current : null;
|
|
35
|
+
}
|
|
36
|
+
export function hasPreviewNavigation(list, missingIds = new Set()) {
|
|
37
|
+
const files = previewNavigationFiles(list).filter((f) => !missingIds.has(f.id));
|
|
38
|
+
return files.length > 1;
|
|
39
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { recentGridColumnsForWidth } from './gridLayout';
|
|
1
2
|
/** Breakpoints shared by the main grid and the Recent strip (Figma desktop / tablet). */
|
|
2
3
|
export const RECENT_FILES_DESKTOP_BREAKPOINT = 1156;
|
|
3
4
|
export const RECENT_FILES_TABLET_BREAKPOINT = 744;
|
|
@@ -6,12 +7,8 @@ export const RECENT_FILES_TABLET_BREAKPOINT = 744;
|
|
|
6
7
|
* One rule for FileBrowser and RecentFiles so the strip matches `getRecentFiles()`.
|
|
7
8
|
*/
|
|
8
9
|
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
10
|
if (containerWidth > RECENT_FILES_TABLET_BREAKPOINT) {
|
|
14
|
-
return
|
|
11
|
+
return recentGridColumnsForWidth(containerWidth) * 2;
|
|
15
12
|
}
|
|
16
13
|
return 4;
|
|
17
14
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type SearchDropdownPhase = 'idle' | 'loading' | 'results' | 'empty';
|
|
2
|
+
export type SearchDropdownPhaseInput = {
|
|
3
|
+
panelOpen: boolean;
|
|
4
|
+
trimmedTerm: string;
|
|
5
|
+
/** The term the debounced search last finished for (empty until first completion). */
|
|
6
|
+
settledTerm: string;
|
|
7
|
+
/** True while a debounced search is in flight for trimmedTerm. */
|
|
8
|
+
queryInFlight: boolean;
|
|
9
|
+
resultCount: number;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* When the panel is open with text: never show the empty card while the query for the current text is pending.
|
|
13
|
+
* `empty` only after the settled term matches the typed term and the result list is empty.
|
|
14
|
+
*/
|
|
15
|
+
export declare function resolveSearchDropdownPhase(input: SearchDropdownPhaseInput): SearchDropdownPhase;
|
|
16
|
+
export declare function shouldShowSearchEmptyState(phase: SearchDropdownPhase): boolean;
|
|
17
|
+
export declare function shouldShowSearchResultsList(phase: SearchDropdownPhase, resultCount: number): boolean;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* When the panel is open with text: never show the empty card while the query for the current text is pending.
|
|
3
|
+
* `empty` only after the settled term matches the typed term and the result list is empty.
|
|
4
|
+
*/
|
|
5
|
+
export function resolveSearchDropdownPhase(input) {
|
|
6
|
+
const { panelOpen, trimmedTerm, settledTerm, queryInFlight, resultCount } = input;
|
|
7
|
+
if (!panelOpen || !trimmedTerm)
|
|
8
|
+
return 'idle';
|
|
9
|
+
if (queryInFlight || settledTerm !== trimmedTerm) {
|
|
10
|
+
if (resultCount > 0)
|
|
11
|
+
return 'results';
|
|
12
|
+
return 'loading';
|
|
13
|
+
}
|
|
14
|
+
if (resultCount > 0)
|
|
15
|
+
return 'results';
|
|
16
|
+
return 'empty';
|
|
17
|
+
}
|
|
18
|
+
export function shouldShowSearchEmptyState(phase) {
|
|
19
|
+
return phase === 'empty';
|
|
20
|
+
}
|
|
21
|
+
export function shouldShowSearchResultsList(phase, resultCount) {
|
|
22
|
+
return resultCount > 0 && (phase === 'results' || phase === 'loading');
|
|
23
|
+
}
|
|
@@ -58,6 +58,7 @@ export async function fetchUserUploadsFromApi(config, options = {}) {
|
|
|
58
58
|
const fileName = (row.file_name || row.fileName || 'upload');
|
|
59
59
|
const url = row.url;
|
|
60
60
|
const mime = inferImageMime((row.mime_type || row.mimeType || ''), fileName, url);
|
|
61
|
+
const libraryFolderPath = (row.library_folder_path ?? row.libraryFolderPath ?? null);
|
|
61
62
|
return {
|
|
62
63
|
id: row.id,
|
|
63
64
|
name: fileName,
|
|
@@ -67,6 +68,7 @@ export async function fetchUserUploadsFromApi(config, options = {}) {
|
|
|
67
68
|
url,
|
|
68
69
|
thumbnail: mime.startsWith('image/') ? url : undefined,
|
|
69
70
|
mimeType: mime || undefined,
|
|
71
|
+
...(libraryFolderPath ? { libraryFolderPath } : {}),
|
|
70
72
|
};
|
|
71
73
|
});
|
|
72
74
|
}
|