@widgetic/file-browser 0.5.17
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/README.md +131 -0
- package/dist/components/FolderTree.svelte +143 -0
- package/dist/components/FolderTree.svelte.d.ts +32 -0
- package/dist/components/core/FileBrowser.css +79 -0
- package/dist/components/core/FileBrowser.svelte +3989 -0
- package/dist/components/core/FileBrowser.svelte.d.ts +55 -0
- package/dist/components/core/FileUploader.svelte +1152 -0
- package/dist/components/core/FileUploader.svelte.d.ts +43 -0
- package/dist/components/core/Header.svelte +143 -0
- package/dist/components/core/Header.svelte.d.ts +36 -0
- package/dist/components/core/RecentFiles.svelte +753 -0
- package/dist/components/core/RecentFiles.svelte.d.ts +37 -0
- package/dist/components/core/UploadStatus.svelte +133 -0
- package/dist/components/core/UploadStatus.svelte.d.ts +28 -0
- package/dist/components/core/UploadStatusList.svelte +138 -0
- package/dist/components/core/UploadStatusList.svelte.d.ts +33 -0
- package/dist/components/core/index.d.ts +4 -0
- package/dist/components/core/index.js +4 -0
- package/dist/components/index.d.ts +6 -0
- package/dist/components/index.js +8 -0
- package/dist/components/items/FileItem.svelte +684 -0
- package/dist/components/items/FileItem.svelte.d.ts +34 -0
- package/dist/components/items/FolderItem.svelte +77 -0
- package/dist/components/items/FolderItem.svelte.d.ts +27 -0
- package/dist/components/items/index.d.ts +2 -0
- package/dist/components/items/index.js +2 -0
- package/dist/components/modals/MoveDialog.svelte +539 -0
- package/dist/components/modals/MoveDialog.svelte.d.ts +32 -0
- package/dist/components/modals/NewFolderButton.svelte +25 -0
- package/dist/components/modals/NewFolderButton.svelte.d.ts +20 -0
- package/dist/components/modals/README.md +99 -0
- package/dist/components/modals/SearchModal.svelte +500 -0
- package/dist/components/modals/SearchModal.svelte.d.ts +28 -0
- package/dist/components/modals/SelectedFilesModal.svelte +291 -0
- package/dist/components/modals/SelectedFilesModal.svelte.d.ts +32 -0
- package/dist/components/modals/index.d.ts +6 -0
- package/dist/components/modals/index.js +9 -0
- package/dist/components/previews/AudioPlayer.svelte +117 -0
- package/dist/components/previews/AudioPlayer.svelte.d.ts +22 -0
- package/dist/components/previews/ErrorPreview.svelte +12 -0
- package/dist/components/previews/ErrorPreview.svelte.d.ts +20 -0
- package/dist/components/previews/FilePreview.svelte +475 -0
- package/dist/components/previews/FilePreview.svelte.d.ts +31 -0
- package/dist/components/previews/FontPreview.svelte +82 -0
- package/dist/components/previews/FontPreview.svelte.d.ts +22 -0
- package/dist/components/previews/ImagePreview.svelte +551 -0
- package/dist/components/previews/ImagePreview.svelte.d.ts +27 -0
- package/dist/components/previews/TextPreview.svelte +92 -0
- package/dist/components/previews/TextPreview.svelte.d.ts +20 -0
- package/dist/components/previews/VideoPlayer.svelte +268 -0
- package/dist/components/previews/VideoPlayer.svelte.d.ts +22 -0
- package/dist/components/previews/WaveformVisualizer.svelte +240 -0
- package/dist/components/previews/WaveformVisualizer.svelte.d.ts +20 -0
- package/dist/components/previews/index.d.ts +8 -0
- package/dist/components/previews/index.js +8 -0
- package/dist/components/ui/ControlToolbar.svelte +342 -0
- package/dist/components/ui/ControlToolbar.svelte.d.ts +36 -0
- package/dist/components/ui/DragSelect.svelte +815 -0
- package/dist/components/ui/DragSelect.svelte.d.ts +31 -0
- package/dist/components/ui/DropdownMenu.svelte +83 -0
- package/dist/components/ui/DropdownMenu.svelte.d.ts +25 -0
- package/dist/components/ui/FileIcon.svelte +65 -0
- package/dist/components/ui/FileIcon.svelte.d.ts +25 -0
- package/dist/components/ui/FileMetadata.svelte +26 -0
- package/dist/components/ui/FileMetadata.svelte.d.ts +21 -0
- package/dist/components/ui/LoadingSkeleton.svelte +26 -0
- package/dist/components/ui/LoadingSkeleton.svelte.d.ts +22 -0
- package/dist/components/ui/SearchResults.svelte +37 -0
- package/dist/components/ui/SearchResults.svelte.d.ts +21 -0
- package/dist/components/ui/VirtualList.svelte +106 -0
- package/dist/components/ui/VirtualList.svelte.d.ts +45 -0
- package/dist/components/ui/index.d.ts +8 -0
- package/dist/components/ui/index.js +8 -0
- package/dist/config.d.ts +7 -0
- package/dist/config.js +14 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +11 -0
- package/dist/static/favicon.png +0 -0
- package/dist/static/files/audio/audio-file.mp3 +0 -0
- package/dist/static/files/document/-missing-file.txt +1 -0
- package/dist/static/files/document/HeliosDesign Website Project Brief Sample.pdf +0 -0
- package/dist/static/files/document/RFP-NEC_Website-Development_2021-August.pdf +0 -0
- package/dist/static/files/document/The World Before Calculus.pdf +0 -0
- package/dist/static/files/document/specs.txt +15 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-Bold.otf +0 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-BoldItalic.otf +0 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-Book.otf +0 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-BookItalic.otf +0 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-Heavy.otf +0 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-HeavyItalic.otf +0 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-Light.otf +0 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-LightItalic.otf +0 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-Medium.otf +0 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-MediumItalic.otf +0 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-Semibold.otf +0 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-SemiboldItalic.otf +0 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-Thin.otf +0 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-ThinItalic.otf +0 -0
- package/dist/static/files/font/Kimpo/Kimpo-Bold.otf +0 -0
- package/dist/static/files/font/Kimpo/Kimpo-Regular.otf +0 -0
- package/dist/static/files/image/image 1.jpg +0 -0
- package/dist/static/files/image/image 10.jpg +0 -0
- package/dist/static/files/image/image 11.jpg +0 -0
- package/dist/static/files/image/image 12.jpg +0 -0
- package/dist/static/files/image/image 13.jpg +0 -0
- package/dist/static/files/image/image 14.jpg +0 -0
- package/dist/static/files/image/image 15.jpg +0 -0
- package/dist/static/files/image/image 16.jpg +0 -0
- package/dist/static/files/image/image 17.jpg +0 -0
- package/dist/static/files/image/image 18.jpg +0 -0
- package/dist/static/files/image/image 19.jpg +0 -0
- package/dist/static/files/image/image 2.jpg +0 -0
- package/dist/static/files/image/image 20.jpg +0 -0
- package/dist/static/files/image/image 21.jpg +0 -0
- package/dist/static/files/image/image 22.jpg +0 -0
- package/dist/static/files/image/image 23.jpg +0 -0
- package/dist/static/files/image/image 24.jpg +0 -0
- package/dist/static/files/image/image 25.jpg +0 -0
- package/dist/static/files/image/image 26.jpg +0 -0
- package/dist/static/files/image/image 27.jpg +0 -0
- package/dist/static/files/image/image 28.jpg +0 -0
- package/dist/static/files/image/image 29.jpg +0 -0
- package/dist/static/files/image/image 3.jpg +0 -0
- package/dist/static/files/image/image 30.jpg +0 -0
- package/dist/static/files/image/image 31.jpg +0 -0
- package/dist/static/files/image/image 32.jpg +0 -0
- package/dist/static/files/image/image 33.jpg +0 -0
- package/dist/static/files/image/image 34.jpg +0 -0
- package/dist/static/files/image/image 35.jpg +0 -0
- package/dist/static/files/image/image 36.jpg +0 -0
- package/dist/static/files/image/image 37.jpg +0 -0
- package/dist/static/files/image/image 38.jpg +0 -0
- package/dist/static/files/image/image 39.jpg +0 -0
- package/dist/static/files/image/image 4.jpg +0 -0
- package/dist/static/files/image/image 40.jpg +0 -0
- package/dist/static/files/image/image 41.jpg +0 -0
- package/dist/static/files/image/image 42.jpg +0 -0
- package/dist/static/files/image/image 43.jpg +0 -0
- package/dist/static/files/image/image 44.jpg +0 -0
- package/dist/static/files/image/image 45.jpg +0 -0
- package/dist/static/files/image/image 46.jpg +0 -0
- package/dist/static/files/image/image 47.jpg +0 -0
- package/dist/static/files/image/image 48.jpg +0 -0
- package/dist/static/files/image/image 49.jpg +0 -0
- package/dist/static/files/image/image 5.jpg +0 -0
- package/dist/static/files/image/image 50.jpg +0 -0
- package/dist/static/files/image/image 51.jpg +0 -0
- package/dist/static/files/image/image 52.jpg +0 -0
- package/dist/static/files/image/image 53.jpg +0 -0
- package/dist/static/files/image/image 54.jpg +0 -0
- package/dist/static/files/image/image 55.jpg +0 -0
- package/dist/static/files/image/image 56.jpg +0 -0
- package/dist/static/files/image/image 57.jpg +0 -0
- package/dist/static/files/image/image 58.jpg +0 -0
- package/dist/static/files/image/image 59.jpg +0 -0
- package/dist/static/files/image/image 6.jpg +0 -0
- package/dist/static/files/image/image 60.jpg +0 -0
- package/dist/static/files/image/image 61.jpg +0 -0
- package/dist/static/files/image/image 62.jpg +0 -0
- package/dist/static/files/image/image 63.jpg +0 -0
- package/dist/static/files/image/image 64.jpg +0 -0
- package/dist/static/files/image/image 65.jpg +0 -0
- package/dist/static/files/image/image 66.jpg +0 -0
- package/dist/static/files/image/image 67.jpg +0 -0
- package/dist/static/files/image/image 68.jpg +0 -0
- package/dist/static/files/image/image 7.jpg +0 -0
- package/dist/static/files/image/image 8.jpg +0 -0
- package/dist/static/files/image/image 9.jpg +0 -0
- package/dist/static/files/svg/astronaut.svg +30 -0
- package/dist/static/files/svg/cook.svg +30 -0
- package/dist/static/files/svg/dj.svg +28 -0
- package/dist/static/files/svg/doctor.svg +29 -0
- package/dist/static/files/svg/farmer.svg +43 -0
- package/dist/static/files/svg/fire fighter.svg +40 -0
- package/dist/static/files/svg/plumber.svg +32 -0
- package/dist/static/files/svg/santa.svg +34 -0
- package/dist/static/files/svg/scientist.svg +31 -0
- package/dist/static/files/svg/student.svg +32 -0
- package/dist/static/files/thumbnail/image 1.jpg +0 -0
- package/dist/static/files/thumbnail/image 10.jpg +0 -0
- package/dist/static/files/thumbnail/image 11.jpg +0 -0
- package/dist/static/files/thumbnail/image 12.jpg +0 -0
- package/dist/static/files/thumbnail/image 13.jpg +0 -0
- package/dist/static/files/thumbnail/image 14.jpg +0 -0
- package/dist/static/files/thumbnail/image 15.jpg +0 -0
- package/dist/static/files/thumbnail/image 16.jpg +0 -0
- package/dist/static/files/thumbnail/image 17.jpg +0 -0
- package/dist/static/files/thumbnail/image 18.jpg +0 -0
- package/dist/static/files/thumbnail/image 19.jpg +0 -0
- package/dist/static/files/thumbnail/image 2.jpg +0 -0
- package/dist/static/files/thumbnail/image 20.jpg +0 -0
- package/dist/static/files/thumbnail/image 21.jpg +0 -0
- package/dist/static/files/thumbnail/image 22.jpg +0 -0
- package/dist/static/files/thumbnail/image 23.jpg +0 -0
- package/dist/static/files/thumbnail/image 24.jpg +0 -0
- package/dist/static/files/thumbnail/image 25.jpg +0 -0
- package/dist/static/files/thumbnail/image 26.jpg +0 -0
- package/dist/static/files/thumbnail/image 27.jpg +0 -0
- package/dist/static/files/thumbnail/image 28.jpg +0 -0
- package/dist/static/files/thumbnail/image 29.jpg +0 -0
- package/dist/static/files/thumbnail/image 3.jpg +0 -0
- package/dist/static/files/thumbnail/image 30.jpg +0 -0
- package/dist/static/files/thumbnail/image 31.jpg +0 -0
- package/dist/static/files/thumbnail/image 32.jpg +0 -0
- package/dist/static/files/thumbnail/image 33.jpg +0 -0
- package/dist/static/files/thumbnail/image 34.jpg +0 -0
- package/dist/static/files/thumbnail/image 35.jpg +0 -0
- package/dist/static/files/thumbnail/image 36.jpg +0 -0
- package/dist/static/files/thumbnail/image 37.jpg +0 -0
- package/dist/static/files/thumbnail/image 38.jpg +0 -0
- package/dist/static/files/thumbnail/image 39.jpg +0 -0
- package/dist/static/files/thumbnail/image 4.jpg +0 -0
- package/dist/static/files/thumbnail/image 40.jpg +0 -0
- package/dist/static/files/thumbnail/image 41.jpg +0 -0
- package/dist/static/files/thumbnail/image 42.jpg +0 -0
- package/dist/static/files/thumbnail/image 43.jpg +0 -0
- package/dist/static/files/thumbnail/image 44.jpg +0 -0
- package/dist/static/files/thumbnail/image 45.jpg +0 -0
- package/dist/static/files/thumbnail/image 46.jpg +0 -0
- package/dist/static/files/thumbnail/image 47.jpg +0 -0
- package/dist/static/files/thumbnail/image 48.jpg +0 -0
- package/dist/static/files/thumbnail/image 49.jpg +0 -0
- package/dist/static/files/thumbnail/image 5.jpg +0 -0
- package/dist/static/files/thumbnail/image 50.jpg +0 -0
- package/dist/static/files/thumbnail/image 51.jpg +0 -0
- package/dist/static/files/thumbnail/image 52.jpg +0 -0
- package/dist/static/files/thumbnail/image 53.jpg +0 -0
- package/dist/static/files/thumbnail/image 54.jpg +0 -0
- package/dist/static/files/thumbnail/image 55.jpg +0 -0
- package/dist/static/files/thumbnail/image 56.jpg +0 -0
- package/dist/static/files/thumbnail/image 57.jpg +0 -0
- package/dist/static/files/thumbnail/image 58.jpg +0 -0
- package/dist/static/files/thumbnail/image 59.jpg +0 -0
- package/dist/static/files/thumbnail/image 6.jpg +0 -0
- package/dist/static/files/thumbnail/image 60.jpg +0 -0
- package/dist/static/files/thumbnail/image 61.jpg +0 -0
- package/dist/static/files/thumbnail/image 62.jpg +0 -0
- package/dist/static/files/thumbnail/image 63.jpg +0 -0
- package/dist/static/files/thumbnail/image 64.jpg +0 -0
- package/dist/static/files/thumbnail/image 65.jpg +0 -0
- package/dist/static/files/thumbnail/image 66.jpg +0 -0
- package/dist/static/files/thumbnail/image 67.jpg +0 -0
- package/dist/static/files/thumbnail/image 68.jpg +0 -0
- package/dist/static/files/thumbnail/image 7.jpg +0 -0
- package/dist/static/files/thumbnail/image 8.jpg +0 -0
- package/dist/static/files/thumbnail/image 9.jpg +0 -0
- package/dist/static/files/video/video-file.mp4 +0 -0
- package/dist/static/files/video/video-file.png +0 -0
- package/dist/static/icons/audio.svg +7 -0
- package/dist/static/icons/check.svg +3 -0
- package/dist/static/icons/checked.svg +4 -0
- package/dist/static/icons/close.svg +11 -0
- package/dist/static/icons/document.svg +11 -0
- package/dist/static/icons/dots.svg +1 -0
- package/dist/static/icons/download.svg +1 -0
- package/dist/static/icons/empty-folder.svg +24 -0
- package/dist/static/icons/error.svg +5 -0
- package/dist/static/icons/file-upload.svg +1 -0
- package/dist/static/icons/folder-plus.svg +1 -0
- package/dist/static/icons/folder.svg +28 -0
- package/dist/static/icons/jump-to-folder.svg +1 -0
- package/dist/static/icons/move.svg +1 -0
- package/dist/static/icons/new-folder.svg +5 -0
- package/dist/static/icons/pdf.svg +6 -0
- package/dist/static/icons/player-pause.svg +1 -0
- package/dist/static/icons/player-play.svg +3 -0
- package/dist/static/icons/plus.svg +1 -0
- package/dist/static/icons/rename.svg +1 -0
- package/dist/static/icons/search.svg +1 -0
- package/dist/static/icons/trash.svg +1 -0
- package/dist/static/icons/unorganized-folder.svg +60 -0
- package/dist/stores/dragStore.d.ts +2 -0
- package/dist/stores/dragStore.js +2 -0
- package/dist/stores/fileStore.d.ts +36 -0
- package/dist/stores/fileStore.js +166 -0
- package/dist/stores/folderCountStore.d.ts +5 -0
- package/dist/stores/folderCountStore.js +49 -0
- package/dist/stores/index.d.ts +7 -0
- package/dist/stores/index.js +8 -0
- package/dist/stores/missingFilesStore.d.ts +3 -0
- package/dist/stores/missingFilesStore.js +14 -0
- package/dist/stores/navigationStore.d.ts +36 -0
- package/dist/stores/navigationStore.js +615 -0
- package/dist/stores/persistentSelectStore.d.ts +17 -0
- package/dist/stores/persistentSelectStore.js +170 -0
- package/dist/stores/searchStore.d.ts +1 -0
- package/dist/stores/searchStore.js +2 -0
- package/dist/stores/uploadApiStore.d.ts +13 -0
- package/dist/stores/uploadApiStore.js +36 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +3 -0
- package/dist/types/pdf.d.ts +3 -0
- package/dist/types.d.ts +23 -0
- package/dist/types.js +1 -0
- package/dist/utils/apiConfig.d.ts +9 -0
- package/dist/utils/apiConfig.js +19 -0
- package/dist/utils/dateUtils.d.ts +2 -0
- package/dist/utils/dateUtils.js +38 -0
- package/dist/utils/fileOperations.d.ts +36 -0
- package/dist/utils/fileOperations.js +573 -0
- package/dist/utils/fileTypes.d.ts +17 -0
- package/dist/utils/fileTypes.js +110 -0
- package/dist/utils/fileUtils.d.ts +15 -0
- package/dist/utils/fileUtils.js +112 -0
- package/dist/utils/folderUtils.d.ts +4 -0
- package/dist/utils/folderUtils.js +26 -0
- package/dist/utils/imageTransform.d.ts +22 -0
- package/dist/utils/imageTransform.js +60 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.js +6 -0
- package/dist/utils/resolveFileUrl.d.ts +6 -0
- package/dist/utils/resolveFileUrl.js +21 -0
- package/dist/utils/userUploadsStorage.d.ts +27 -0
- package/dist/utils/userUploadsStorage.js +168 -0
- package/dist/utils/widgeticTusUpload.d.ts +18 -0
- package/dist/utils/widgeticTusUpload.js +131 -0
- package/dist/utils/widgeticUpload.d.ts +29 -0
- package/dist/utils/widgeticUpload.js +105 -0
- package/package.json +156 -0
|
@@ -0,0 +1,615 @@
|
|
|
1
|
+
import { writable, derived, get } from 'svelte/store';
|
|
2
|
+
import { currentFolder } from './fileStore';
|
|
3
|
+
import { getPathNamesFromIds } from '../utils/fileOperations';
|
|
4
|
+
import { fileStore } from './fileStore';
|
|
5
|
+
// Remove $app/environment import
|
|
6
|
+
// import { browser } from '$app/environment';
|
|
7
|
+
// Browser detection that works across bundlers
|
|
8
|
+
const browser = typeof window !== 'undefined';
|
|
9
|
+
// CONSTANTS
|
|
10
|
+
const showLogs = false;
|
|
11
|
+
// Create a derived store for path names that any component can subscribe to
|
|
12
|
+
export const currentPathNames = derived(currentFolder, ($currentFolder) => getPathNamesFromIds($currentFolder));
|
|
13
|
+
// Export the currentFolder store for external use
|
|
14
|
+
export { currentFolder };
|
|
15
|
+
// Create a navigation action store
|
|
16
|
+
export const navigationActions = writable({
|
|
17
|
+
navigateToPath: (path) => { },
|
|
18
|
+
navigateToIndex: (index) => { },
|
|
19
|
+
});
|
|
20
|
+
// Initialize the navigation actions
|
|
21
|
+
export function initializeNavigation(navigate) {
|
|
22
|
+
navigationActions.set({
|
|
23
|
+
navigateToPath: navigate,
|
|
24
|
+
navigateToIndex: (index) => {
|
|
25
|
+
const unsubscribe = currentFolder.subscribe(currentPath => {
|
|
26
|
+
if (index === -1) {
|
|
27
|
+
navigate([]);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
navigate(currentPath.slice(0, index + 1));
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
unsubscribe();
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
// Helper function to check if paths are equal
|
|
38
|
+
function arePathsEqual(path1, path2) {
|
|
39
|
+
return path1.length === path2.length &&
|
|
40
|
+
path1.every((id, index) => id === path2[index]);
|
|
41
|
+
}
|
|
42
|
+
export function getStorageKey(instanceId = 'default') {
|
|
43
|
+
return `file-browser-navigation-${instanceId}`;
|
|
44
|
+
}
|
|
45
|
+
function createNavigationStore(instanceId = 'default') {
|
|
46
|
+
const STORAGE_KEY = getStorageKey(instanceId);
|
|
47
|
+
// Get the initial state from storage
|
|
48
|
+
const storedState = getStoredState(instanceId);
|
|
49
|
+
const initialState = storedState || {
|
|
50
|
+
pathsArray: [[]],
|
|
51
|
+
currentIndex: 0
|
|
52
|
+
};
|
|
53
|
+
if (showLogs)
|
|
54
|
+
console.log('Initializing navigation store with state:', initialState);
|
|
55
|
+
const { subscribe, set, update } = writable(initialState);
|
|
56
|
+
// Add a flag to track if we should validate paths
|
|
57
|
+
let isFileStoreInitialized = false;
|
|
58
|
+
let hasData = false;
|
|
59
|
+
// Subscribe to fileStore to know when it's initialized
|
|
60
|
+
fileStore.subscribe(store => {
|
|
61
|
+
const wasInitialized = isFileStoreInitialized;
|
|
62
|
+
const previousHasData = hasData;
|
|
63
|
+
isFileStoreInitialized = !!(store && store.root && store.root.children);
|
|
64
|
+
hasData = isFileStoreInitialized && Array.isArray(store?.root?.children) && store.root.children.length > 0;
|
|
65
|
+
if (showLogs)
|
|
66
|
+
console.log('File store initialization status:', {
|
|
67
|
+
wasInitialized,
|
|
68
|
+
isNowInitialized: isFileStoreInitialized,
|
|
69
|
+
previousHasData,
|
|
70
|
+
nowHasData: hasData,
|
|
71
|
+
hasRoot: !!store?.root,
|
|
72
|
+
hasChildren: !!store?.root?.children,
|
|
73
|
+
childrenCount: store?.root?.children?.length
|
|
74
|
+
});
|
|
75
|
+
// If we just got data and have a stored path, validate it now
|
|
76
|
+
if (hasData && !previousHasData && storedState) {
|
|
77
|
+
if (showLogs)
|
|
78
|
+
console.log('File store now has data, validating stored path:', storedState);
|
|
79
|
+
update(state => {
|
|
80
|
+
const currentPath = state.pathsArray[state.currentIndex];
|
|
81
|
+
let currentFolder = store.root;
|
|
82
|
+
let validPath = true;
|
|
83
|
+
for (const folderId of currentPath) {
|
|
84
|
+
if (!currentFolder.children) {
|
|
85
|
+
validPath = false;
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
const nextFolder = currentFolder.children.find(child => child.id === folderId && child.type === 'folder');
|
|
89
|
+
if (!nextFolder) {
|
|
90
|
+
validPath = false;
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
currentFolder = nextFolder;
|
|
94
|
+
}
|
|
95
|
+
if (!validPath) {
|
|
96
|
+
console.warn('Stored path invalid after data load, resetting to root:', currentPath);
|
|
97
|
+
const rootState = {
|
|
98
|
+
pathsArray: [[]],
|
|
99
|
+
currentIndex: 0
|
|
100
|
+
};
|
|
101
|
+
try {
|
|
102
|
+
localStorage.setItem(STORAGE_KEY, JSON.stringify(rootState));
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
console.error('Error saving navigation state:', error);
|
|
106
|
+
}
|
|
107
|
+
return rootState;
|
|
108
|
+
}
|
|
109
|
+
return state;
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
return {
|
|
114
|
+
subscribe,
|
|
115
|
+
navigateToFolder: (newPath, forceNavigation = false) => {
|
|
116
|
+
update(state => {
|
|
117
|
+
// Check if we're already at this path and skip only if not forcing navigation
|
|
118
|
+
const currentPath = state.pathsArray[state.currentIndex];
|
|
119
|
+
if (!forceNavigation && arePathsEqual(currentPath, newPath)) {
|
|
120
|
+
if (showLogs)
|
|
121
|
+
console.log('Navigation: Already at this path, skipping navigation', {
|
|
122
|
+
current: currentPath,
|
|
123
|
+
new: newPath
|
|
124
|
+
});
|
|
125
|
+
return state;
|
|
126
|
+
}
|
|
127
|
+
// Only validate path if file store is initialized AND has data
|
|
128
|
+
let validPath = true;
|
|
129
|
+
if (isFileStoreInitialized && hasData) {
|
|
130
|
+
if (showLogs)
|
|
131
|
+
console.log('Validating path:', {
|
|
132
|
+
path: newPath,
|
|
133
|
+
fileStoreState: get(fileStore)
|
|
134
|
+
});
|
|
135
|
+
// Validate that all folders in the path exist
|
|
136
|
+
const store = get(fileStore);
|
|
137
|
+
let currentFolder = store.root;
|
|
138
|
+
for (const folderId of newPath) {
|
|
139
|
+
if (showLogs)
|
|
140
|
+
console.log('Checking folder:', {
|
|
141
|
+
folderId,
|
|
142
|
+
hasChildren: !!currentFolder.children,
|
|
143
|
+
childrenCount: currentFolder.children?.length,
|
|
144
|
+
availableFolders: currentFolder.children
|
|
145
|
+
?.filter(child => child.type === 'folder')
|
|
146
|
+
.map(child => ({ id: child.id, name: child.name }))
|
|
147
|
+
});
|
|
148
|
+
if (!currentFolder.children) {
|
|
149
|
+
validPath = false;
|
|
150
|
+
console.warn('Folder has no children:', currentFolder);
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
const nextFolder = currentFolder.children.find(child => child.id === folderId && child.type === 'folder');
|
|
154
|
+
if (!nextFolder) {
|
|
155
|
+
validPath = false;
|
|
156
|
+
console.warn('Folder not found:', {
|
|
157
|
+
searchedId: folderId,
|
|
158
|
+
availableFolders: currentFolder.children
|
|
159
|
+
.filter(child => child.type === 'folder')
|
|
160
|
+
.map(child => ({ id: child.id, name: child.name }))
|
|
161
|
+
});
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
currentFolder = nextFolder;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
// If forceNavigation is true, we'll proceed even without validation
|
|
169
|
+
if (showLogs)
|
|
170
|
+
console.log('File store not ready for validation, proceeding with navigation:', {
|
|
171
|
+
forceNavigation,
|
|
172
|
+
pathLength: newPath.length
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
// If path is invalid and not forcing navigation, reset to root
|
|
176
|
+
if (!validPath && !forceNavigation) {
|
|
177
|
+
console.warn('Navigation: Invalid path detected, resetting to root', {
|
|
178
|
+
attemptedPath: newPath,
|
|
179
|
+
reason: 'Path validation failed',
|
|
180
|
+
forceNavigation
|
|
181
|
+
});
|
|
182
|
+
const rootState = {
|
|
183
|
+
pathsArray: [[]],
|
|
184
|
+
currentIndex: 0
|
|
185
|
+
};
|
|
186
|
+
if (browser) {
|
|
187
|
+
try {
|
|
188
|
+
localStorage.setItem(STORAGE_KEY, JSON.stringify(rootState));
|
|
189
|
+
}
|
|
190
|
+
catch (error) {
|
|
191
|
+
console.error('Error saving navigation state:', error);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return rootState;
|
|
195
|
+
}
|
|
196
|
+
// Proceed with navigation
|
|
197
|
+
// Check if we're on a page refresh scenario by looking if this path
|
|
198
|
+
// already exists at the end of the history
|
|
199
|
+
const lastPathIndex = state.pathsArray.length - 1;
|
|
200
|
+
const lastPath = lastPathIndex >= 0 ? state.pathsArray[lastPathIndex] : null;
|
|
201
|
+
// Get the current persistHistory setting
|
|
202
|
+
const isPersistHistoryEnabled = get(persistHistory);
|
|
203
|
+
// SIMPLIFY: Always check if the path is already the last item in the history,
|
|
204
|
+
// and if so, just skip adding a duplicate regardless of other conditions
|
|
205
|
+
if (lastPath && arePathsEqual(lastPath, newPath)) {
|
|
206
|
+
if (showLogs)
|
|
207
|
+
console.log('Navigation: Preventing duplicate history entry - path is already the last item', {
|
|
208
|
+
pathsArray: state.pathsArray.length,
|
|
209
|
+
currentIndex: state.currentIndex,
|
|
210
|
+
lastIndex: lastPathIndex,
|
|
211
|
+
newPath: newPath.join('/')
|
|
212
|
+
});
|
|
213
|
+
// If we're not already at the last index, update to it
|
|
214
|
+
if (state.currentIndex !== lastPathIndex) {
|
|
215
|
+
const newState = {
|
|
216
|
+
...state,
|
|
217
|
+
currentIndex: lastPathIndex
|
|
218
|
+
};
|
|
219
|
+
if (browser) {
|
|
220
|
+
try {
|
|
221
|
+
localStorage.setItem(STORAGE_KEY, JSON.stringify(newState));
|
|
222
|
+
}
|
|
223
|
+
catch (error) {
|
|
224
|
+
console.error('Error saving navigation state:', error);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return newState;
|
|
228
|
+
}
|
|
229
|
+
// Otherwise just return the current state unchanged
|
|
230
|
+
return state;
|
|
231
|
+
}
|
|
232
|
+
// Also check if the new path already exists anywhere in the history
|
|
233
|
+
// This helps prevent duplicate entries in non-consecutive positions
|
|
234
|
+
const existingPathIndex = state.pathsArray.findIndex(path => arePathsEqual(path, newPath));
|
|
235
|
+
if (existingPathIndex !== -1) {
|
|
236
|
+
if (showLogs)
|
|
237
|
+
console.log('Navigation: Preventing duplicate history entry - path exists elsewhere in history', {
|
|
238
|
+
pathsArray: state.pathsArray.length,
|
|
239
|
+
existingPathIndex,
|
|
240
|
+
currentIndex: state.currentIndex,
|
|
241
|
+
newPath: newPath.join('/')
|
|
242
|
+
});
|
|
243
|
+
// Navigate to the existing path's index
|
|
244
|
+
const newState = {
|
|
245
|
+
...state,
|
|
246
|
+
currentIndex: existingPathIndex
|
|
247
|
+
};
|
|
248
|
+
if (browser) {
|
|
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
|
+
}
|
|
257
|
+
return newState;
|
|
258
|
+
}
|
|
259
|
+
// If we get here, we're adding a new unique path to the history
|
|
260
|
+
// Remove any forward history when navigating to a new path
|
|
261
|
+
const newPathsArray = [...state.pathsArray.slice(0, state.currentIndex + 1), newPath];
|
|
262
|
+
const newState = {
|
|
263
|
+
pathsArray: newPathsArray,
|
|
264
|
+
currentIndex: newPathsArray.length - 1
|
|
265
|
+
};
|
|
266
|
+
if (showLogs)
|
|
267
|
+
console.log('Navigation: Adding new path to history', {
|
|
268
|
+
pathsArrayLength: newPathsArray.length,
|
|
269
|
+
currentIndex: newState.currentIndex,
|
|
270
|
+
newPath: newPath.join('/')
|
|
271
|
+
});
|
|
272
|
+
// Save to localStorage if persistHistory is enabled
|
|
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
|
+
}
|
|
282
|
+
return newState;
|
|
283
|
+
});
|
|
284
|
+
},
|
|
285
|
+
navigateBack: () => {
|
|
286
|
+
update(state => {
|
|
287
|
+
if (state.currentIndex > 0) {
|
|
288
|
+
const newState = {
|
|
289
|
+
...state,
|
|
290
|
+
currentIndex: state.currentIndex - 1
|
|
291
|
+
};
|
|
292
|
+
if (browser) {
|
|
293
|
+
localStorage.setItem(STORAGE_KEY, JSON.stringify(newState));
|
|
294
|
+
}
|
|
295
|
+
return newState;
|
|
296
|
+
}
|
|
297
|
+
return state;
|
|
298
|
+
});
|
|
299
|
+
},
|
|
300
|
+
navigateForward: () => {
|
|
301
|
+
update(state => {
|
|
302
|
+
if (state.currentIndex < state.pathsArray.length - 1) {
|
|
303
|
+
const newState = {
|
|
304
|
+
...state,
|
|
305
|
+
currentIndex: state.currentIndex + 1
|
|
306
|
+
};
|
|
307
|
+
if (browser) {
|
|
308
|
+
localStorage.setItem(STORAGE_KEY, JSON.stringify(newState));
|
|
309
|
+
}
|
|
310
|
+
return newState;
|
|
311
|
+
}
|
|
312
|
+
return state;
|
|
313
|
+
});
|
|
314
|
+
},
|
|
315
|
+
reset: () => {
|
|
316
|
+
const initialState = {
|
|
317
|
+
pathsArray: [[]],
|
|
318
|
+
currentIndex: 0
|
|
319
|
+
};
|
|
320
|
+
set(initialState);
|
|
321
|
+
if (browser) {
|
|
322
|
+
localStorage.removeItem(STORAGE_KEY);
|
|
323
|
+
}
|
|
324
|
+
},
|
|
325
|
+
cleanupPaths: (deletedFolderId) => {
|
|
326
|
+
update(state => {
|
|
327
|
+
// Store the current path before cleanup
|
|
328
|
+
const currentPath = state.pathsArray[state.currentIndex];
|
|
329
|
+
const isCurrentPathRoot = currentPath.length === 0;
|
|
330
|
+
const currentPathContainsDeletedFolder = currentPath.includes(deletedFolderId);
|
|
331
|
+
if (showLogs)
|
|
332
|
+
console.log('Cleaning up paths after folder deletion:', {
|
|
333
|
+
deletedFolderId,
|
|
334
|
+
currentPath,
|
|
335
|
+
isCurrentPathRoot,
|
|
336
|
+
currentPathContainsDeletedFolder,
|
|
337
|
+
totalPaths: state.pathsArray.length
|
|
338
|
+
});
|
|
339
|
+
// Create new paths array without paths containing deleted folder
|
|
340
|
+
let newPaths = [];
|
|
341
|
+
// Clone and cleanup the paths array
|
|
342
|
+
const pathsToProcess = [...state.pathsArray];
|
|
343
|
+
pathsToProcess.forEach(path => {
|
|
344
|
+
// Skip if path contains deleted folder
|
|
345
|
+
if (path.includes(deletedFolderId)) {
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
// Skip if this path is same as the last added path
|
|
349
|
+
if (newPaths.length > 0 && arePathsEqual(path, newPaths[newPaths.length - 1])) {
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
newPaths.push(path);
|
|
353
|
+
});
|
|
354
|
+
// Clear the temporary array
|
|
355
|
+
pathsToProcess.length = 0;
|
|
356
|
+
// Determine the new current index
|
|
357
|
+
let newCurrentIndex;
|
|
358
|
+
if (currentPathContainsDeletedFolder) {
|
|
359
|
+
// If current path contained the deleted folder, find its parent path
|
|
360
|
+
const deletedFolderIndex = currentPath.indexOf(deletedFolderId);
|
|
361
|
+
const parentPath = deletedFolderIndex > 0
|
|
362
|
+
? currentPath.slice(0, deletedFolderIndex)
|
|
363
|
+
: [];
|
|
364
|
+
// Find the parent path in the new paths array
|
|
365
|
+
const parentPathIndex = newPaths.findIndex(path => arePathsEqual(path, parentPath));
|
|
366
|
+
// Use parent path if found, otherwise use root (first path)
|
|
367
|
+
newCurrentIndex = parentPathIndex >= 0 ? parentPathIndex : 0;
|
|
368
|
+
if (showLogs)
|
|
369
|
+
console.log('Current path contained deleted folder, navigating to parent:', {
|
|
370
|
+
parentPath,
|
|
371
|
+
parentPathIndex,
|
|
372
|
+
newCurrentIndex
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
else {
|
|
376
|
+
// Current path didn't contain deleted folder, try to maintain it
|
|
377
|
+
const currentPathIndex = newPaths.findIndex(path => arePathsEqual(path, currentPath));
|
|
378
|
+
// Use current path if found, otherwise use the last path
|
|
379
|
+
newCurrentIndex = currentPathIndex >= 0
|
|
380
|
+
? currentPathIndex
|
|
381
|
+
: (isCurrentPathRoot ? 0 : newPaths.length - 1);
|
|
382
|
+
if (showLogs)
|
|
383
|
+
console.log('Maintaining current path after deletion:', {
|
|
384
|
+
currentPathIndex,
|
|
385
|
+
newCurrentIndex,
|
|
386
|
+
isCurrentPathRoot
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
// Ensure we always have at least the root path
|
|
390
|
+
if (newPaths.length === 0) {
|
|
391
|
+
newPaths.push([]);
|
|
392
|
+
newCurrentIndex = 0;
|
|
393
|
+
if (showLogs)
|
|
394
|
+
console.log('No valid paths remain, resetting to root');
|
|
395
|
+
}
|
|
396
|
+
const newState = {
|
|
397
|
+
pathsArray: newPaths,
|
|
398
|
+
currentIndex: newCurrentIndex
|
|
399
|
+
};
|
|
400
|
+
if (showLogs)
|
|
401
|
+
console.log('Final navigation state after cleanup:', {
|
|
402
|
+
pathsCount: newPaths.length,
|
|
403
|
+
currentIndex: newCurrentIndex,
|
|
404
|
+
currentPath: newPaths[newCurrentIndex]
|
|
405
|
+
});
|
|
406
|
+
// Save to localStorage
|
|
407
|
+
if (browser) {
|
|
408
|
+
try {
|
|
409
|
+
localStorage.setItem(STORAGE_KEY, JSON.stringify(newState));
|
|
410
|
+
// Also clean up any other related localStorage items
|
|
411
|
+
for (const key of Object.keys(localStorage)) {
|
|
412
|
+
if (key.startsWith(`${STORAGE_KEY}-`)) {
|
|
413
|
+
localStorage.removeItem(key);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
catch (error) {
|
|
418
|
+
console.error('Error saving navigation state:', error);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
return newState;
|
|
422
|
+
});
|
|
423
|
+
},
|
|
424
|
+
updateMovedFolderPaths: (movedFolderId, newParentPath) => {
|
|
425
|
+
update(state => {
|
|
426
|
+
if (showLogs)
|
|
427
|
+
console.log('Updating paths for moved folder:', {
|
|
428
|
+
movedFolderId,
|
|
429
|
+
newParentPath,
|
|
430
|
+
currentPaths: state.pathsArray
|
|
431
|
+
});
|
|
432
|
+
// Update paths that contain the moved folder
|
|
433
|
+
const updatedPaths = state.pathsArray.map(path => {
|
|
434
|
+
// Find if this path contains the moved folder
|
|
435
|
+
const movedFolderIndex = path.indexOf(movedFolderId);
|
|
436
|
+
if (movedFolderIndex !== -1) {
|
|
437
|
+
// If this path contains the moved folder:
|
|
438
|
+
// 1. Get any subfolders that were inside the moved folder
|
|
439
|
+
const subfolders = path.slice(movedFolderIndex + 1);
|
|
440
|
+
// 2. Build the new complete path:
|
|
441
|
+
const newPath = [
|
|
442
|
+
...newParentPath, // Parent folder path (e.g., ['Onboarding Content'])
|
|
443
|
+
movedFolderId, // The moved folder (e.g., 'Design Process')
|
|
444
|
+
...subfolders // Any subfolders that were inside
|
|
445
|
+
];
|
|
446
|
+
if (showLogs)
|
|
447
|
+
console.log('Updated path:', {
|
|
448
|
+
original: path,
|
|
449
|
+
new: newPath,
|
|
450
|
+
details: {
|
|
451
|
+
parentPath: newParentPath,
|
|
452
|
+
movedFolder: movedFolderId,
|
|
453
|
+
subfolders
|
|
454
|
+
},
|
|
455
|
+
reason: 'Contains moved folder'
|
|
456
|
+
});
|
|
457
|
+
return newPath;
|
|
458
|
+
}
|
|
459
|
+
if (showLogs)
|
|
460
|
+
console.log('Keeping original path:', {
|
|
461
|
+
path,
|
|
462
|
+
reason: 'Does not contain moved folder'
|
|
463
|
+
});
|
|
464
|
+
return path;
|
|
465
|
+
});
|
|
466
|
+
// Remove any duplicate paths that might have been created
|
|
467
|
+
const uniquePaths = updatedPaths.filter((path, index, array) => {
|
|
468
|
+
const firstIndex = array.findIndex(p => p.length === path.length && p.every((id, i) => id === path[i]));
|
|
469
|
+
return index === firstIndex;
|
|
470
|
+
});
|
|
471
|
+
// Find the current path in the new paths array
|
|
472
|
+
const currentPath = state.pathsArray[state.currentIndex];
|
|
473
|
+
const newCurrentIndex = uniquePaths.findIndex(path => path.length === currentPath.length &&
|
|
474
|
+
path.every((id, i) => id === currentPath[i]));
|
|
475
|
+
const newState = {
|
|
476
|
+
pathsArray: uniquePaths,
|
|
477
|
+
currentIndex: newCurrentIndex >= 0 ? newCurrentIndex : uniquePaths.length - 1
|
|
478
|
+
};
|
|
479
|
+
if (showLogs)
|
|
480
|
+
console.log('Final navigation state:', {
|
|
481
|
+
paths: newState.pathsArray,
|
|
482
|
+
currentIndex: newState.currentIndex,
|
|
483
|
+
currentPath: newState.pathsArray[newState.currentIndex]
|
|
484
|
+
});
|
|
485
|
+
// Save to localStorage
|
|
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
|
+
}
|
|
494
|
+
return newState;
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
// Create derived stores for common navigation state
|
|
500
|
+
export function createCurrentPathStore(navigationStore) {
|
|
501
|
+
return derived(navigationStore, $nav => $nav.pathsArray[$nav.currentIndex]);
|
|
502
|
+
}
|
|
503
|
+
export function createCanGoBackStore(navigationStore) {
|
|
504
|
+
return derived(navigationStore, $nav => $nav.currentIndex > 0);
|
|
505
|
+
}
|
|
506
|
+
export function createCanGoForwardStore(navigationStore) {
|
|
507
|
+
return derived(navigationStore, $nav => $nav.currentIndex < $nav.pathsArray.length - 1);
|
|
508
|
+
}
|
|
509
|
+
// Store instances cache
|
|
510
|
+
const navigationStores = {};
|
|
511
|
+
export function getNavigationStore(instanceId = 'default') {
|
|
512
|
+
if (!navigationStores[instanceId]) {
|
|
513
|
+
navigationStores[instanceId] = createNavigationStore(instanceId);
|
|
514
|
+
}
|
|
515
|
+
return navigationStores[instanceId];
|
|
516
|
+
}
|
|
517
|
+
export function getStoredState(instanceId) {
|
|
518
|
+
const STORAGE_KEY = getStorageKey(instanceId);
|
|
519
|
+
try {
|
|
520
|
+
if (showLogs)
|
|
521
|
+
console.log('Getting stored state for instance:', instanceId);
|
|
522
|
+
if (!browser) {
|
|
523
|
+
if (showLogs)
|
|
524
|
+
console.log('Not in browser context, skipping localStorage');
|
|
525
|
+
return null;
|
|
526
|
+
}
|
|
527
|
+
const stored = localStorage.getItem(STORAGE_KEY);
|
|
528
|
+
if (!stored) {
|
|
529
|
+
if (showLogs)
|
|
530
|
+
console.log('No stored state found');
|
|
531
|
+
return null;
|
|
532
|
+
}
|
|
533
|
+
const state = JSON.parse(stored);
|
|
534
|
+
if (showLogs)
|
|
535
|
+
console.log('Found stored state:', {
|
|
536
|
+
pathsArray: state.pathsArray,
|
|
537
|
+
currentIndex: state.currentIndex,
|
|
538
|
+
currentPath: state.pathsArray[state.currentIndex]
|
|
539
|
+
});
|
|
540
|
+
// During initialization, always return the stored state without validation
|
|
541
|
+
// We'll validate it later when the file data is loaded
|
|
542
|
+
const store = get(fileStore);
|
|
543
|
+
const isInitialized = !!(store && store.root && store.root.children);
|
|
544
|
+
const hasData = isInitialized && Array.isArray(store?.root?.children) && store.root.children.length > 0;
|
|
545
|
+
if (showLogs)
|
|
546
|
+
console.log('File store state when retrieving stored path:', {
|
|
547
|
+
isInitialized,
|
|
548
|
+
hasData,
|
|
549
|
+
hasRoot: !!store?.root,
|
|
550
|
+
hasChildren: !!store?.root?.children,
|
|
551
|
+
childrenCount: store?.root?.children?.length
|
|
552
|
+
});
|
|
553
|
+
if (!isInitialized || !hasData) {
|
|
554
|
+
if (showLogs)
|
|
555
|
+
console.log('File store not ready, returning stored state without validation');
|
|
556
|
+
return state;
|
|
557
|
+
}
|
|
558
|
+
// Only proceed with validation if the file store is initialized AND has data
|
|
559
|
+
const currentPath = state.pathsArray[state.currentIndex];
|
|
560
|
+
let currentFolder = store.root;
|
|
561
|
+
let validPath = true;
|
|
562
|
+
for (const folderId of currentPath) {
|
|
563
|
+
if (showLogs)
|
|
564
|
+
console.log('Validating stored path folder:', {
|
|
565
|
+
folderId,
|
|
566
|
+
hasChildren: !!currentFolder.children,
|
|
567
|
+
childrenCount: currentFolder.children?.length,
|
|
568
|
+
availableFolders: currentFolder.children
|
|
569
|
+
?.filter(child => child.type === 'folder')
|
|
570
|
+
.map(child => ({ id: child.id, name: child.name }))
|
|
571
|
+
});
|
|
572
|
+
if (!currentFolder.children) {
|
|
573
|
+
validPath = false;
|
|
574
|
+
if (showLogs)
|
|
575
|
+
console.warn('Stored path folder has no children:', currentFolder);
|
|
576
|
+
break;
|
|
577
|
+
}
|
|
578
|
+
const nextFolder = currentFolder.children.find(child => child.id === folderId && child.type === 'folder');
|
|
579
|
+
if (!nextFolder) {
|
|
580
|
+
validPath = false;
|
|
581
|
+
if (showLogs)
|
|
582
|
+
console.warn('Stored path folder not found:', {
|
|
583
|
+
searchedId: folderId,
|
|
584
|
+
availableFolders: currentFolder.children
|
|
585
|
+
.filter(child => child.type === 'folder')
|
|
586
|
+
.map(child => ({ id: child.id, name: child.name }))
|
|
587
|
+
});
|
|
588
|
+
break;
|
|
589
|
+
}
|
|
590
|
+
currentFolder = nextFolder;
|
|
591
|
+
}
|
|
592
|
+
// If path is invalid, return null to trigger reset to root
|
|
593
|
+
if (!validPath) {
|
|
594
|
+
if (showLogs)
|
|
595
|
+
console.warn('Invalid stored path detected, will reset to root:', {
|
|
596
|
+
attemptedPath: currentPath,
|
|
597
|
+
reason: 'Path validation failed'
|
|
598
|
+
});
|
|
599
|
+
// Remove the stored state from localStorage
|
|
600
|
+
if (browser) {
|
|
601
|
+
localStorage.removeItem(STORAGE_KEY);
|
|
602
|
+
}
|
|
603
|
+
// Return null to trigger reset to root
|
|
604
|
+
return null;
|
|
605
|
+
}
|
|
606
|
+
return state;
|
|
607
|
+
}
|
|
608
|
+
catch (error) {
|
|
609
|
+
if (showLogs)
|
|
610
|
+
console.error('Error reading navigation state:', error);
|
|
611
|
+
return null;
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
// Create a store for persisting navigation history
|
|
615
|
+
export const persistHistory = writable(true);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { FileSystemItem } from '../types';
|
|
2
|
+
import type { FileFilterType } from '../utils/fileTypes';
|
|
3
|
+
interface StoredSelections {
|
|
4
|
+
[filterType: string]: string[];
|
|
5
|
+
}
|
|
6
|
+
export declare const persistentSelectStore: {
|
|
7
|
+
getSelected: (filterType: FileFilterType) => string[];
|
|
8
|
+
toggleSelection: (file: FileSystemItem, filterType: FileFilterType) => void;
|
|
9
|
+
setSelections: (filterType: FileFilterType, selectedIds: string[]) => void;
|
|
10
|
+
clearSelections: (filterType: FileFilterType) => void;
|
|
11
|
+
getValidSelections: (filterType: FileFilterType, files: FileSystemItem[]) => string[];
|
|
12
|
+
set(this: void, value: StoredSelections): void;
|
|
13
|
+
update(this: void, updater: import("svelte/store").Updater<StoredSelections>): void;
|
|
14
|
+
subscribe(this: void, run: import("svelte/store").Subscriber<StoredSelections>, invalidate?: () => void): import("svelte/store").Unsubscriber;
|
|
15
|
+
};
|
|
16
|
+
export declare const validSelections: import("svelte/store").Readable<(filterType: FileFilterType, files: FileSystemItem[]) => any[]>;
|
|
17
|
+
export {};
|