@widgetic/file-browser 0.5.18 → 0.5.20

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 (30) hide show
  1. package/dist/components/core/FileBrowser.svelte +149 -1331
  2. package/dist/components/core/FileUploader.svelte +4 -4
  3. package/dist/components/core/Header.svelte +3 -3
  4. package/dist/components/core/RecentFiles.svelte +7 -43
  5. package/dist/components/items/FileItem.svelte +10 -43
  6. package/dist/components/items/FileItem.svelte.d.ts +1 -0
  7. package/dist/components/items/FolderItem.svelte +4 -12
  8. package/dist/components/items/FolderItem.svelte.d.ts +1 -0
  9. package/dist/components/modals/MoveDialog.svelte +17 -17
  10. package/dist/components/modals/SearchModal.svelte +30 -41
  11. package/dist/components/modals/SelectedFilesModal.svelte +2 -2
  12. package/dist/components/previews/AudioPlayer.svelte +1 -1
  13. package/dist/components/previews/FilePreview.svelte +7 -7
  14. package/dist/components/previews/ImagePreview.svelte +13 -13
  15. package/dist/components/previews/VideoPlayer.svelte +1 -1
  16. package/dist/components/ui/DragSelect.svelte +73 -52
  17. package/dist/components/ui/DropdownMenu.svelte +1 -1
  18. package/dist/components/ui/VirtualList.svelte +20 -10
  19. package/dist/data/demoContent.json +1171 -0
  20. package/dist/stores/fileStore.js +1 -1
  21. package/dist/stores/persistentSelectStore.d.ts +1 -0
  22. package/dist/stores/persistentSelectStore.js +23 -0
  23. package/dist/stores/viewportStore.d.ts +5 -0
  24. package/dist/stores/viewportStore.js +19 -0
  25. package/dist/utils/fileOperations.js +17 -14
  26. package/dist/utils/resolveFileUrl.js +6 -2
  27. package/dist/utils/userUploadsStorage.d.ts +5 -0
  28. package/dist/utils/userUploadsStorage.js +15 -6
  29. package/dist/utils/widgeticUpload.d.ts +1 -0
  30. package/package.json +8 -8
@@ -69,7 +69,7 @@ export const sortedFiles = derived([fileStore, sortCriteria, sortDirection], ([$
69
69
  return $sortDirection === 'asc' ? comparison : -comparison;
70
70
  });
71
71
  const result = {
72
- ...fileStore,
72
+ ...$fileStore,
73
73
  root: {
74
74
  ...$fileStore.root,
75
75
  children: sortedChildren
@@ -7,6 +7,7 @@ export declare const persistentSelectStore: {
7
7
  getSelected: (filterType: FileFilterType) => string[];
8
8
  toggleSelection: (file: FileSystemItem, filterType: FileFilterType) => void;
9
9
  setSelections: (filterType: FileFilterType, selectedIds: string[]) => void;
10
+ removeSelection: (fileId: string, filterType: FileFilterType) => void;
10
11
  clearSelections: (filterType: FileFilterType) => void;
11
12
  getValidSelections: (filterType: FileFilterType, files: FileSystemItem[]) => string[];
12
13
  set(this: void, value: StoredSelections): void;
@@ -99,6 +99,29 @@ function createPersistentSelectStore() {
99
99
  [filterType]: selectedIds
100
100
  }));
101
101
  },
102
+ // Remove a single selection for a filter type without toggling
103
+ removeSelection: (fileId, filterType) => {
104
+ selections.update(stored => {
105
+ const currentSelections = stored[filterType] || [];
106
+ if (!currentSelections.includes(fileId))
107
+ return stored;
108
+ const updatedSelections = { ...stored };
109
+ updatedSelections[filterType] = currentSelections.filter(id => id !== fileId);
110
+ // Also remove from 'all' if present
111
+ if (filterType !== 'all' && stored['all']?.includes(fileId)) {
112
+ updatedSelections['all'] = stored['all'].filter(id => id !== fileId);
113
+ }
114
+ // If removing from 'all', remove from all other filters as well
115
+ if (filterType === 'all') {
116
+ Object.keys(stored).forEach(key => {
117
+ if (key !== 'all' && stored[key]?.includes(fileId)) {
118
+ updatedSelections[key] = stored[key].filter(id => id !== fileId);
119
+ }
120
+ });
121
+ }
122
+ return updatedSelections;
123
+ });
124
+ },
102
125
  // Clear selections for a filter type
103
126
  clearSelections: (filterType) => {
104
127
  selections.update(stored => {
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Shared media query store tracking whether the viewport is mobile width (<= 768px).
3
+ * Uses window.matchMedia so it only fires when crossing the breakpoint rather than on every resize pixel.
4
+ */
5
+ export declare const isMobileStore: import("svelte/store").Readable<boolean>;
@@ -0,0 +1,19 @@
1
+ import { readable } from 'svelte/store';
2
+ import { browser } from '$app/environment';
3
+ /**
4
+ * Shared media query store tracking whether the viewport is mobile width (<= 768px).
5
+ * Uses window.matchMedia so it only fires when crossing the breakpoint rather than on every resize pixel.
6
+ */
7
+ export const isMobileStore = readable(browser ? window.innerWidth <= 768 : false, (set) => {
8
+ if (!browser)
9
+ return;
10
+ const mediaQueryList = window.matchMedia('(max-width: 768px)');
11
+ const handleMediaQueryChange = (event) => {
12
+ set(event.matches);
13
+ };
14
+ set(mediaQueryList.matches);
15
+ mediaQueryList.addEventListener('change', handleMediaQueryChange);
16
+ return () => {
17
+ mediaQueryList.removeEventListener('change', handleMediaQueryChange);
18
+ };
19
+ });
@@ -88,7 +88,7 @@ export async function renameItem(itemId, newName) {
88
88
  }
89
89
  // Don't rename if name hasn't changed
90
90
  if (item.name === newName) {
91
- console.log('Name unchanged, skipping rename');
91
+ // console.log('Name unchanged, skipping rename');
92
92
  return false;
93
93
  }
94
94
  // For files, preserve the extension to maintain correct file type
@@ -103,7 +103,7 @@ export async function renameItem(itemId, newName) {
103
103
  // Preserve the original extension
104
104
  const originalExtension = currentNameParts[currentNameParts.length - 1];
105
105
  finalName = `${newName}.${originalExtension}`;
106
- console.log(`Preserving file extension for type consistency: ${newName} → ${finalName}`);
106
+ // console.log(`Preserving file extension for type consistency: ${newName} → ${finalName}`);
107
107
  }
108
108
  }
109
109
  // Get current sort settings
@@ -200,7 +200,7 @@ export async function renameItem(itemId, newName) {
200
200
  // Update all instances of the old folder name in saved paths
201
201
  navigationHistory.paths = navigationHistory.paths.map((savedPath) => savedPath.map(segment => segment === item.name ? finalName : segment));
202
202
  localStorage.setItem('navigationHistory', JSON.stringify(navigationHistory));
203
- console.log('Updated navigation history in localStorage after rename');
203
+ // console.log('Updated navigation history in localStorage after rename');
204
204
  }
205
205
  }
206
206
  catch (error) {
@@ -212,12 +212,12 @@ export async function renameItem(itemId, newName) {
212
212
  return path;
213
213
  });
214
214
  // Log the updates
215
- console.log('File system updated after rename:', {
216
- itemId,
217
- newName: finalName,
218
- success,
219
- time: updatedTime
220
- });
215
+ // console.log('File system updated after rename:', {
216
+ // itemId,
217
+ // newName: finalName,
218
+ // success,
219
+ // time: updatedTime
220
+ // });
221
221
  return success;
222
222
  }
223
223
  catch (error) {
@@ -240,7 +240,7 @@ async function mockRenameAPI(itemId, newName) {
240
240
  }
241
241
  // Skip blob URL checks for files since they can cause ERR_METHOD_NOT_SUPPORTED
242
242
  if (item.type === 'file' && item.url && item.url.startsWith('blob:')) {
243
- console.log('Skipping blob URL check for file:', item.name);
243
+ // console.log('Skipping blob URL check for file:', item.name);
244
244
  // Just return success for blob URLs
245
245
  return {
246
246
  success: true
@@ -295,8 +295,11 @@ export function moveItem(itemId, targetFolderId) {
295
295
  const rootChildren = store.root.children ?? [];
296
296
  if (removeItem(rootChildren) && itemToMove) {
297
297
  store.root.children = rootChildren;
298
- // If targetFolderId is empty string, add to root
299
- if (targetFolderId === '') {
298
+ // If targetFolderId is root, add to root
299
+ const isTargetRoot = targetFolderId === '' ||
300
+ targetFolderId === 'root' ||
301
+ Boolean(store.root && targetFolderId === store.root.id);
302
+ if (isTargetRoot) {
300
303
  store.root.children.push(itemToMove);
301
304
  store.root.modified = updatedTime;
302
305
  success = true;
@@ -352,10 +355,10 @@ async function mockDeleteAPI(itemId, thumbnailPaths, filePaths) {
352
355
  await new Promise(resolve => setTimeout(resolve, 1000));
353
356
  // In a real API, we would delete both the original files and their thumbnails
354
357
  if (thumbnailPaths) {
355
- console.log('Would delete thumbnails at:', thumbnailPaths);
358
+ // console.log('Would delete thumbnails at:', thumbnailPaths);
356
359
  }
357
360
  if (filePaths) {
358
- console.log('Would delete files at:', filePaths);
361
+ // console.log('Would delete files at:', filePaths);
359
362
  }
360
363
  // Mock success response
361
364
  return {
@@ -8,8 +8,12 @@ export function buildFileUrl(basePath, filePath) {
8
8
  if (!basePath)
9
9
  return filePath.startsWith('/') ? filePath : `/${filePath}`;
10
10
  const normalizedBase = basePath.endsWith('/') ? basePath : `${basePath}/`;
11
- const normalizedPath = filePath.startsWith('/') ? filePath.slice(1) : filePath;
12
- return `${normalizedBase}${normalizedPath}`;
11
+ const cleanPath = filePath.startsWith('/') ? filePath : `/${filePath}`;
12
+ if (cleanPath.startsWith(normalizedBase)) {
13
+ return cleanPath;
14
+ }
15
+ const cleanRelative = filePath.startsWith('/') ? filePath.slice(1) : filePath;
16
+ return `${normalizedBase}${cleanRelative}`;
13
17
  }
14
18
  export function resolveFileItemUrl(item, basePath) {
15
19
  if (item.type !== 'file' || !item.url)
@@ -8,6 +8,11 @@ export declare function loadUserUploads(): Promise<FileSystemItem[]>;
8
8
  * Fire-and-forget: callers do not await persistence.
9
9
  */
10
10
  export declare function saveUserUpload(file: FileSystemItem): void;
11
+ /**
12
+ * Persist multiple uploads into L1 in a single atomic transaction.
13
+ * Eliminates IndexedDB race conditions and reduces write overhead when hydrating batches of files.
14
+ */
15
+ export declare function saveUserUploadsBatch(files: FileSystemItem[]): void;
11
16
  /**
12
17
  * Load the saved library tree children from L1 (legacy fallback).
13
18
  */
@@ -41,12 +41,20 @@ export async function loadUserUploads() {
41
41
  * Fire-and-forget: callers do not await persistence.
42
42
  */
43
43
  export function saveUserUpload(file) {
44
- if (file.type !== 'file')
44
+ saveUserUploadsBatch([file]);
45
+ }
46
+ /**
47
+ * Persist multiple uploads into L1 in a single atomic transaction.
48
+ * Eliminates IndexedDB race conditions and reduces write overhead when hydrating batches of files.
49
+ */
50
+ export function saveUserUploadsBatch(files) {
51
+ const validFiles = files.filter((f) => f.type === 'file');
52
+ if (validFiles.length === 0)
45
53
  return;
46
54
  const ownerId = ownerIdOrNull();
47
55
  if (!ownerId)
48
56
  return;
49
- const entry = {
57
+ const entries = validFiles.map((file) => ({
50
58
  id: file.id,
51
59
  name: file.name,
52
60
  type: 'file',
@@ -56,16 +64,17 @@ export function saveUserUpload(file) {
56
64
  modified: file.modified || new Date().toISOString(),
57
65
  hash: file.hash,
58
66
  mimeType: file.mimeType,
59
- };
67
+ }));
60
68
  void (async () => {
61
69
  try {
62
70
  const existing = await loadAllPersistedUploads();
63
- const merged = existing.filter((f) => f.id !== entry.id);
64
- merged.unshift(entry);
71
+ const newIds = new Set(entries.map((e) => e.id));
72
+ const filteredExisting = existing.filter((f) => !newIds.has(f.id));
73
+ const merged = [...entries, ...filteredExisting];
65
74
  await writeEntity(ownerId, UPLOADS_KIND, entityKey(), merged);
66
75
  }
67
76
  catch (error) {
68
- console.error('[userUploadsStorage] Failed to persist upload:', error);
77
+ console.error('[userUploadsStorage] Failed to persist uploads batch:', error);
69
78
  }
70
79
  })();
71
80
  }
@@ -11,6 +11,7 @@ export type WidgeticUploadResult = {
11
11
  modified: string;
12
12
  url: string;
13
13
  thumbnail?: string;
14
+ mimeType?: string;
14
15
  };
15
16
  error?: string;
16
17
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@widgetic/file-browser",
3
- "version": "0.5.18",
3
+ "version": "0.5.20",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -87,6 +87,8 @@
87
87
  "@types/eslint": "^9.6.0",
88
88
  "@types/fs-extra": "^11.0.4",
89
89
  "@types/node": "^22.13.4",
90
+ "@widgetic/cache-layer": "^0.1.1",
91
+ "@widgetic/design-system": "^0.3.89",
90
92
  "autoprefixer": "^10.4.20",
91
93
  "eslint": "^9.0.0",
92
94
  "eslint-config-prettier": "^9.1.0",
@@ -98,20 +100,18 @@
98
100
  "prettier-plugin-svelte": "^3.1.2",
99
101
  "svelte-check": "^4.5.0",
100
102
  "typescript-eslint": "^8.0.0",
101
- "vite-imagetools": "^7.0.4",
102
- "@widgetic/cache-layer": "^0.1.1",
103
- "@widgetic/design-system": "^0.3.89"
103
+ "vite-imagetools": "^7.0.4"
104
104
  },
105
105
  "peerDependencies": {
106
106
  "@sveltejs/kit": "^2.20.7",
107
- "pdfjs-dist": "^4.10.38",
108
107
  "@widgetic/cache-layer": "^0.1.1",
109
- "@widgetic/design-system": ">=0.3.0"
108
+ "@widgetic/design-system": ">=0.3.0",
109
+ "pdfjs-dist": "^4.10.38"
110
110
  },
111
111
  "dependencies": {
112
112
  "@melt-ui/svelte": "^0.86.3",
113
113
  "@sveltejs/adapter-node": "^5.2.4",
114
- "@sveltejs/kit": "^2.61.1",
114
+ "@sveltejs/kit": "^2.20.7",
115
115
  "@sveltejs/package": "^2.3.7",
116
116
  "@sveltejs/vite-plugin-svelte": "^5.1.1",
117
117
  "@tabler/icons-svelte": "^3.24.0",
@@ -126,7 +126,7 @@
126
126
  "pdfjs-dist": "^4.10.38",
127
127
  "postcss": "^8.4.47",
128
128
  "shadcn-svelte": "latest",
129
- "svelte": "^5.56.1",
129
+ "svelte": "^5.56.4",
130
130
  "svelte-dnd-action": "^0.9.50",
131
131
  "svelte-forms-lib": "^2.0.1",
132
132
  "svelte-infinite-scroll": "^2.0.1",