@widgetic/file-browser 0.5.48 → 0.5.49
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/actions/dragSelectedToFolder.js +115 -104
- package/dist/components/FolderTree.svelte.d.ts +7 -4
- package/dist/components/core/FileBrowser.svelte +1 -3
- package/dist/components/core/dropzoneClick.js +2 -3
- package/dist/components/previews/FilePreview.svelte.d.ts +2 -2
- package/dist/config.js +3 -4
- package/dist/i18n/context.js +2 -2
- package/dist/i18n/errors.js +1 -2
- package/dist/i18n/messages.js +2 -2
- package/dist/i18n/text.js +2 -2
- package/dist/mediaLibrary/capabilities.js +3 -4
- package/dist/mediaLibrary/context.js +3 -4
- package/dist/mediaLibrary/errors.js +35 -46
- package/dist/mediaLibrary/normalize.js +42 -45
- package/dist/mediaLibrary/paging.js +45 -100
- package/dist/mediaLibrary/resolve.js +95 -214
- package/dist/mediaLibrary/treeOps.js +20 -40
- package/dist/mediaLibrary/urls.js +10 -12
- package/dist/mediaLibrary/widgetic.js +54 -140
- package/dist/stores/dragStore.js +1 -1
- package/dist/stores/fileStore.d.ts +3 -3
- package/dist/stores/fileStore.js +37 -44
- package/dist/stores/folderCountStore.js +11 -12
- package/dist/stores/missingFilesStore.js +3 -3
- package/dist/stores/navigationStore.d.ts +1 -1
- package/dist/stores/navigationStore.js +178 -217
- package/dist/stores/persistentSelectStore.d.ts +1 -1
- package/dist/stores/persistentSelectStore.js +94 -117
- package/dist/stores/searchStore.js +1 -1
- package/dist/stores/uploadApiStore.js +7 -7
- package/dist/stores/viewportStore.js +4 -4
- package/dist/types/index.js +1 -0
- package/dist/utils/apiConfig.js +9 -9
- package/dist/utils/brandKitLibraryTree.js +42 -57
- package/dist/utils/dateUtils.js +9 -11
- package/dist/utils/dragToFolder/batchMoveResult.js +54 -114
- package/dist/utils/dragToFolder/folderDropTarget.js +17 -23
- package/dist/utils/dragToFolder/springStep.js +3 -4
- package/dist/utils/fileGoneProbe.js +16 -65
- package/dist/utils/fileKinds.js +13 -14
- package/dist/utils/fileNames.js +7 -7
- package/dist/utils/fileOperations.js +332 -440
- package/dist/utils/fileTypes.js +14 -19
- package/dist/utils/fileUtils.js +31 -85
- package/dist/utils/folderUtils.js +4 -5
- package/dist/utils/gridLayout.js +7 -7
- package/dist/utils/imagePreviewCache.js +15 -26
- package/dist/utils/imagePreviewFrame.js +13 -13
- package/dist/utils/imagePreviewVisualState.js +4 -5
- package/dist/utils/imageTransform.js +14 -27
- package/dist/utils/itemMenuCapabilities.js +7 -7
- package/dist/utils/libraryTree.js +39 -55
- package/dist/utils/pendingUploadDeletes.js +113 -289
- package/dist/utils/previewKeys.js +1 -1
- package/dist/utils/previewListNavigation.js +11 -13
- package/dist/utils/previewNavigation.js +7 -10
- package/dist/utils/recentFiles.js +6 -16
- package/dist/utils/recentFilesLimit.js +2 -2
- package/dist/utils/removeItems.js +29 -61
- package/dist/utils/resolveFileUrl.js +6 -6
- package/dist/utils/safeText.js +12 -14
- package/dist/utils/searchDropdownPhase.js +2 -2
- package/dist/utils/searchItems.js +14 -30
- package/dist/utils/searchNavigation.js +5 -5
- package/dist/utils/uploadAuth.js +36 -111
- package/dist/utils/uploadDisplayProgress.js +1 -1
- package/dist/utils/uploadLimits.js +66 -138
- package/dist/utils/uploadListReconcile.js +11 -24
- package/dist/utils/uploadPanelDismiss.js +1 -1
- package/dist/utils/uploadPanelProgress.js +4 -4
- package/dist/utils/uploadProgressMath.js +11 -13
- package/dist/utils/uploadRefusals.js +24 -40
- package/dist/utils/uploadResponseMapping.js +8 -9
- package/dist/utils/uploadUiHelpers.js +17 -17
- package/dist/utils/userUploadsStorage.js +133 -270
- package/dist/utils/videoFrame.js +2 -2
- package/dist/utils/widgeticDelete.js +30 -103
- package/dist/utils/widgeticTusUpload.js +105 -189
- package/dist/utils/widgeticUpload.js +62 -130
- package/dist/utils/xhrMultipartUpload.js +116 -164
- package/package.json +1 -1
|
@@ -1,23 +1,3 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
13
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
14
|
-
if (ar || !(i in from)) {
|
|
15
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
16
|
-
ar[i] = from[i];
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
20
|
-
};
|
|
21
1
|
import { writable, derived, get } from 'svelte/store';
|
|
22
2
|
import { currentFolder } from './fileStore';
|
|
23
3
|
import { getPathNamesFromIds } from '../utils/fileOperations';
|
|
@@ -25,26 +5,24 @@ import { fileStore } from './fileStore';
|
|
|
25
5
|
// Remove $app/environment import
|
|
26
6
|
// import { browser } from '$app/environment';
|
|
27
7
|
// Browser detection that works across bundlers
|
|
28
|
-
|
|
8
|
+
const browser = typeof window !== 'undefined';
|
|
29
9
|
// CONSTANTS
|
|
30
|
-
|
|
10
|
+
const showLogs = false;
|
|
31
11
|
// Create a derived store for path names that any component can subscribe to
|
|
32
|
-
export
|
|
33
|
-
return getPathNamesFromIds($currentFolder);
|
|
34
|
-
});
|
|
12
|
+
export const currentPathNames = derived(currentFolder, ($currentFolder) => getPathNamesFromIds($currentFolder));
|
|
35
13
|
// Export the currentFolder store for external use
|
|
36
14
|
export { currentFolder };
|
|
37
15
|
// Create a navigation action store
|
|
38
|
-
export
|
|
39
|
-
navigateToPath:
|
|
40
|
-
navigateToIndex:
|
|
16
|
+
export const navigationActions = writable({
|
|
17
|
+
navigateToPath: (path) => { },
|
|
18
|
+
navigateToIndex: (index) => { },
|
|
41
19
|
});
|
|
42
20
|
// Initialize the navigation actions
|
|
43
21
|
export function initializeNavigation(navigate) {
|
|
44
22
|
navigationActions.set({
|
|
45
23
|
navigateToPath: navigate,
|
|
46
|
-
navigateToIndex:
|
|
47
|
-
|
|
24
|
+
navigateToIndex: (index) => {
|
|
25
|
+
const unsubscribe = currentFolder.subscribe(currentPath => {
|
|
48
26
|
if (index === -1) {
|
|
49
27
|
navigate([]);
|
|
50
28
|
}
|
|
@@ -59,15 +37,14 @@ export function initializeNavigation(navigate) {
|
|
|
59
37
|
// Helper function to check if paths are equal
|
|
60
38
|
function arePathsEqual(path1, path2) {
|
|
61
39
|
return path1.length === path2.length &&
|
|
62
|
-
path1.every(
|
|
40
|
+
path1.every((id, index) => id === path2[index]);
|
|
63
41
|
}
|
|
64
|
-
export function getStorageKey(instanceId) {
|
|
65
|
-
|
|
66
|
-
return "file-browser-navigation-".concat(instanceId);
|
|
42
|
+
export function getStorageKey(instanceId = 'default') {
|
|
43
|
+
return `file-browser-navigation-${instanceId}`;
|
|
67
44
|
}
|
|
68
45
|
/** Shared localStorage id for file pickers inside the Widgetic editor (folder path only, not filter/sort). */
|
|
69
|
-
export
|
|
70
|
-
|
|
46
|
+
export const WIDGETIC_EDITOR_FILE_PICKER_INSTANCE_ID = 'widgetic-editor-file-picker';
|
|
47
|
+
const persistFolderPathByInstance = {};
|
|
71
48
|
/** Toggles whether this instance may write its folder path to localStorage (set from FileBrowser props). */
|
|
72
49
|
export function setPersistFolderPath(instanceId, enabled) {
|
|
73
50
|
persistFolderPathByInstance[instanceId] = enabled;
|
|
@@ -86,67 +63,59 @@ function saveNavigationStateToStorage(instanceId, state) {
|
|
|
86
63
|
console.error('Error saving navigation state:', error);
|
|
87
64
|
}
|
|
88
65
|
}
|
|
89
|
-
function createNavigationStore(instanceId) {
|
|
90
|
-
|
|
91
|
-
var STORAGE_KEY = getStorageKey(instanceId);
|
|
66
|
+
function createNavigationStore(instanceId = 'default') {
|
|
67
|
+
const STORAGE_KEY = getStorageKey(instanceId);
|
|
92
68
|
// Get the initial state from storage
|
|
93
|
-
|
|
94
|
-
|
|
69
|
+
const storedState = getStoredState(instanceId);
|
|
70
|
+
const initialState = storedState || {
|
|
95
71
|
pathsArray: [[]],
|
|
96
72
|
currentIndex: 0
|
|
97
73
|
};
|
|
98
74
|
if (showLogs)
|
|
99
75
|
console.log('Initializing navigation store with state:', initialState);
|
|
100
|
-
|
|
76
|
+
const { subscribe, set, update } = writable(initialState);
|
|
101
77
|
// Add a flag to track if we should validate paths
|
|
102
|
-
|
|
103
|
-
|
|
78
|
+
let isFileStoreInitialized = false;
|
|
79
|
+
let hasData = false;
|
|
104
80
|
// Subscribe to fileStore to know when it's initialized
|
|
105
|
-
fileStore.subscribe(
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
var previousHasData = hasData;
|
|
81
|
+
fileStore.subscribe(store => {
|
|
82
|
+
const wasInitialized = isFileStoreInitialized;
|
|
83
|
+
const previousHasData = hasData;
|
|
109
84
|
isFileStoreInitialized = !!(store && store.root && store.root.children);
|
|
110
|
-
hasData = isFileStoreInitialized && Array.isArray(
|
|
85
|
+
hasData = isFileStoreInitialized && Array.isArray(store?.root?.children) && store.root.children.length > 0;
|
|
111
86
|
if (showLogs)
|
|
112
87
|
console.log('File store initialization status:', {
|
|
113
|
-
wasInitialized
|
|
88
|
+
wasInitialized,
|
|
114
89
|
isNowInitialized: isFileStoreInitialized,
|
|
115
|
-
previousHasData
|
|
90
|
+
previousHasData,
|
|
116
91
|
nowHasData: hasData,
|
|
117
|
-
hasRoot: !!
|
|
118
|
-
hasChildren: !!
|
|
119
|
-
childrenCount:
|
|
92
|
+
hasRoot: !!store?.root,
|
|
93
|
+
hasChildren: !!store?.root?.children,
|
|
94
|
+
childrenCount: store?.root?.children?.length
|
|
120
95
|
});
|
|
121
96
|
// If we just got data and have a stored path, validate it now
|
|
122
97
|
if (hasData && !previousHasData && storedState) {
|
|
123
98
|
if (showLogs)
|
|
124
99
|
console.log('File store now has data, validating stored path:', storedState);
|
|
125
|
-
update(
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
100
|
+
update(state => {
|
|
101
|
+
const currentPath = state.pathsArray[state.currentIndex];
|
|
102
|
+
let currentFolder = store.root;
|
|
103
|
+
let validPath = true;
|
|
104
|
+
for (const folderId of currentPath) {
|
|
130
105
|
if (!currentFolder.children) {
|
|
131
106
|
validPath = false;
|
|
132
|
-
|
|
107
|
+
break;
|
|
133
108
|
}
|
|
134
|
-
|
|
109
|
+
const nextFolder = currentFolder.children.find(child => child.id === folderId && child.type === 'folder');
|
|
135
110
|
if (!nextFolder) {
|
|
136
111
|
validPath = false;
|
|
137
|
-
|
|
112
|
+
break;
|
|
138
113
|
}
|
|
139
114
|
currentFolder = nextFolder;
|
|
140
|
-
};
|
|
141
|
-
for (var _i = 0, currentPath_1 = currentPath; _i < currentPath_1.length; _i++) {
|
|
142
|
-
var folderId = currentPath_1[_i];
|
|
143
|
-
var state_1 = _loop_1(folderId);
|
|
144
|
-
if (state_1 === "break")
|
|
145
|
-
break;
|
|
146
115
|
}
|
|
147
116
|
if (!validPath) {
|
|
148
117
|
console.warn('Stored path invalid after data load, resetting to root:', currentPath);
|
|
149
|
-
|
|
118
|
+
const rootState = {
|
|
150
119
|
pathsArray: [[]],
|
|
151
120
|
currentIndex: 0
|
|
152
121
|
};
|
|
@@ -158,13 +127,11 @@ function createNavigationStore(instanceId) {
|
|
|
158
127
|
}
|
|
159
128
|
});
|
|
160
129
|
return {
|
|
161
|
-
subscribe
|
|
162
|
-
navigateToFolder:
|
|
163
|
-
|
|
164
|
-
update(function (state) {
|
|
165
|
-
var _a, _b;
|
|
130
|
+
subscribe,
|
|
131
|
+
navigateToFolder: (newPath, forceNavigation = false) => {
|
|
132
|
+
update(state => {
|
|
166
133
|
// Check if we're already at this path and skip only if not forcing navigation
|
|
167
|
-
|
|
134
|
+
const currentPath = state.pathsArray[state.currentIndex];
|
|
168
135
|
if (!forceNavigation && arePathsEqual(currentPath, newPath)) {
|
|
169
136
|
if (showLogs)
|
|
170
137
|
console.log('Navigation: Already at this path, skipping navigation', {
|
|
@@ -174,7 +141,7 @@ function createNavigationStore(instanceId) {
|
|
|
174
141
|
return state;
|
|
175
142
|
}
|
|
176
143
|
// Only validate path if file store is initialized AND has data
|
|
177
|
-
|
|
144
|
+
let validPath = true;
|
|
178
145
|
if (isFileStoreInitialized && hasData) {
|
|
179
146
|
if (showLogs)
|
|
180
147
|
console.log('Validating path:', {
|
|
@@ -182,46 +149,42 @@ function createNavigationStore(instanceId) {
|
|
|
182
149
|
fileStoreState: get(fileStore)
|
|
183
150
|
});
|
|
184
151
|
// Validate that all folders in the path exist
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
152
|
+
const store = get(fileStore);
|
|
153
|
+
let currentFolder = store.root;
|
|
154
|
+
for (const folderId of newPath) {
|
|
188
155
|
if (showLogs)
|
|
189
156
|
console.log('Checking folder:', {
|
|
190
|
-
folderId
|
|
191
|
-
hasChildren: !!
|
|
192
|
-
childrenCount:
|
|
193
|
-
availableFolders:
|
|
157
|
+
folderId,
|
|
158
|
+
hasChildren: !!currentFolder.children,
|
|
159
|
+
childrenCount: currentFolder.children?.length,
|
|
160
|
+
availableFolders: currentFolder.children
|
|
161
|
+
?.filter(child => child.type === 'folder')
|
|
162
|
+
.map(child => ({ id: child.id, name: child.name }))
|
|
194
163
|
});
|
|
195
|
-
if (!
|
|
164
|
+
if (!currentFolder.children) {
|
|
196
165
|
validPath = false;
|
|
197
|
-
console.warn('Folder has no children:',
|
|
198
|
-
|
|
166
|
+
console.warn('Folder has no children:', currentFolder);
|
|
167
|
+
break;
|
|
199
168
|
}
|
|
200
|
-
|
|
169
|
+
const nextFolder = currentFolder.children.find(child => child.id === folderId && child.type === 'folder');
|
|
201
170
|
if (!nextFolder) {
|
|
202
171
|
validPath = false;
|
|
203
172
|
console.warn('Folder not found:', {
|
|
204
173
|
searchedId: folderId,
|
|
205
|
-
availableFolders:
|
|
206
|
-
.filter(
|
|
207
|
-
.map(
|
|
174
|
+
availableFolders: currentFolder.children
|
|
175
|
+
.filter(child => child.type === 'folder')
|
|
176
|
+
.map(child => ({ id: child.id, name: child.name }))
|
|
208
177
|
});
|
|
209
|
-
return "break";
|
|
210
|
-
}
|
|
211
|
-
currentFolder_1 = nextFolder;
|
|
212
|
-
};
|
|
213
|
-
for (var _i = 0, newPath_1 = newPath; _i < newPath_1.length; _i++) {
|
|
214
|
-
var folderId = newPath_1[_i];
|
|
215
|
-
var state_2 = _loop_2(folderId);
|
|
216
|
-
if (state_2 === "break")
|
|
217
178
|
break;
|
|
179
|
+
}
|
|
180
|
+
currentFolder = nextFolder;
|
|
218
181
|
}
|
|
219
182
|
}
|
|
220
183
|
else {
|
|
221
184
|
// If forceNavigation is true, we'll proceed even without validation
|
|
222
185
|
if (showLogs)
|
|
223
186
|
console.log('File store not ready for validation, proceeding with navigation:', {
|
|
224
|
-
forceNavigation
|
|
187
|
+
forceNavigation,
|
|
225
188
|
pathLength: newPath.length
|
|
226
189
|
});
|
|
227
190
|
}
|
|
@@ -230,9 +193,9 @@ function createNavigationStore(instanceId) {
|
|
|
230
193
|
console.warn('Navigation: Invalid path detected, resetting to root', {
|
|
231
194
|
attemptedPath: newPath,
|
|
232
195
|
reason: 'Path validation failed',
|
|
233
|
-
forceNavigation
|
|
196
|
+
forceNavigation
|
|
234
197
|
});
|
|
235
|
-
|
|
198
|
+
const rootState = {
|
|
236
199
|
pathsArray: [[]],
|
|
237
200
|
currentIndex: 0
|
|
238
201
|
};
|
|
@@ -242,8 +205,8 @@ function createNavigationStore(instanceId) {
|
|
|
242
205
|
// Proceed with navigation
|
|
243
206
|
// Check if we're on a page refresh scenario by looking if this path
|
|
244
207
|
// already exists at the end of the history
|
|
245
|
-
|
|
246
|
-
|
|
208
|
+
const lastPathIndex = state.pathsArray.length - 1;
|
|
209
|
+
const lastPath = lastPathIndex >= 0 ? state.pathsArray[lastPathIndex] : null;
|
|
247
210
|
// SIMPLIFY: Always check if the path is already the last item in the history,
|
|
248
211
|
// and if so, just skip adding a duplicate regardless of other conditions
|
|
249
212
|
if (lastPath && arePathsEqual(lastPath, newPath)) {
|
|
@@ -256,33 +219,39 @@ function createNavigationStore(instanceId) {
|
|
|
256
219
|
});
|
|
257
220
|
// If we're not already at the last index, update to it
|
|
258
221
|
if (state.currentIndex !== lastPathIndex) {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
222
|
+
const newState = {
|
|
223
|
+
...state,
|
|
224
|
+
currentIndex: lastPathIndex
|
|
225
|
+
};
|
|
226
|
+
saveNavigationStateToStorage(instanceId, newState);
|
|
227
|
+
return newState;
|
|
262
228
|
}
|
|
263
229
|
// Otherwise just return the current state unchanged
|
|
264
230
|
return state;
|
|
265
231
|
}
|
|
266
232
|
// Also check if the new path already exists anywhere in the history
|
|
267
233
|
// This helps prevent duplicate entries in non-consecutive positions
|
|
268
|
-
|
|
234
|
+
const existingPathIndex = state.pathsArray.findIndex(path => arePathsEqual(path, newPath));
|
|
269
235
|
if (existingPathIndex !== -1) {
|
|
270
236
|
if (showLogs)
|
|
271
237
|
console.log('Navigation: Preventing duplicate history entry - path exists elsewhere in history', {
|
|
272
238
|
pathsArray: state.pathsArray.length,
|
|
273
|
-
existingPathIndex
|
|
239
|
+
existingPathIndex,
|
|
274
240
|
currentIndex: state.currentIndex,
|
|
275
241
|
newPath: newPath.join('/')
|
|
276
242
|
});
|
|
277
243
|
// Navigate to the existing path's index
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
244
|
+
const newState = {
|
|
245
|
+
...state,
|
|
246
|
+
currentIndex: existingPathIndex
|
|
247
|
+
};
|
|
248
|
+
saveNavigationStateToStorage(instanceId, newState);
|
|
249
|
+
return newState;
|
|
281
250
|
}
|
|
282
251
|
// If we get here, we're adding a new unique path to the history
|
|
283
252
|
// Remove any forward history when navigating to a new path
|
|
284
|
-
|
|
285
|
-
|
|
253
|
+
const newPathsArray = [...state.pathsArray.slice(0, state.currentIndex + 1), newPath];
|
|
254
|
+
const newState = {
|
|
286
255
|
pathsArray: newPathsArray,
|
|
287
256
|
currentIndex: newPathsArray.length - 1
|
|
288
257
|
};
|
|
@@ -296,28 +265,34 @@ function createNavigationStore(instanceId) {
|
|
|
296
265
|
return newState;
|
|
297
266
|
});
|
|
298
267
|
},
|
|
299
|
-
navigateBack:
|
|
300
|
-
update(
|
|
268
|
+
navigateBack: () => {
|
|
269
|
+
update(state => {
|
|
301
270
|
if (state.currentIndex > 0) {
|
|
302
|
-
|
|
271
|
+
const newState = {
|
|
272
|
+
...state,
|
|
273
|
+
currentIndex: state.currentIndex - 1
|
|
274
|
+
};
|
|
303
275
|
saveNavigationStateToStorage(instanceId, newState);
|
|
304
276
|
return newState;
|
|
305
277
|
}
|
|
306
278
|
return state;
|
|
307
279
|
});
|
|
308
280
|
},
|
|
309
|
-
navigateForward:
|
|
310
|
-
update(
|
|
281
|
+
navigateForward: () => {
|
|
282
|
+
update(state => {
|
|
311
283
|
if (state.currentIndex < state.pathsArray.length - 1) {
|
|
312
|
-
|
|
284
|
+
const newState = {
|
|
285
|
+
...state,
|
|
286
|
+
currentIndex: state.currentIndex + 1
|
|
287
|
+
};
|
|
313
288
|
saveNavigationStateToStorage(instanceId, newState);
|
|
314
289
|
return newState;
|
|
315
290
|
}
|
|
316
291
|
return state;
|
|
317
292
|
});
|
|
318
293
|
},
|
|
319
|
-
reset:
|
|
320
|
-
|
|
294
|
+
reset: () => {
|
|
295
|
+
const initialState = {
|
|
321
296
|
pathsArray: [[]],
|
|
322
297
|
currentIndex: 0
|
|
323
298
|
};
|
|
@@ -331,25 +306,25 @@ function createNavigationStore(instanceId) {
|
|
|
331
306
|
}
|
|
332
307
|
}
|
|
333
308
|
},
|
|
334
|
-
cleanupPaths:
|
|
335
|
-
update(
|
|
309
|
+
cleanupPaths: (deletedFolderId) => {
|
|
310
|
+
update(state => {
|
|
336
311
|
// Store the current path before cleanup
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
312
|
+
const currentPath = state.pathsArray[state.currentIndex];
|
|
313
|
+
const isCurrentPathRoot = currentPath.length === 0;
|
|
314
|
+
const currentPathContainsDeletedFolder = currentPath.includes(deletedFolderId);
|
|
340
315
|
if (showLogs)
|
|
341
316
|
console.log('Cleaning up paths after folder deletion:', {
|
|
342
|
-
deletedFolderId
|
|
343
|
-
currentPath
|
|
344
|
-
isCurrentPathRoot
|
|
345
|
-
currentPathContainsDeletedFolder
|
|
317
|
+
deletedFolderId,
|
|
318
|
+
currentPath,
|
|
319
|
+
isCurrentPathRoot,
|
|
320
|
+
currentPathContainsDeletedFolder,
|
|
346
321
|
totalPaths: state.pathsArray.length
|
|
347
322
|
});
|
|
348
323
|
// Create new paths array without paths containing deleted folder
|
|
349
|
-
|
|
324
|
+
let newPaths = [];
|
|
350
325
|
// Clone and cleanup the paths array
|
|
351
|
-
|
|
352
|
-
pathsToProcess.forEach(
|
|
326
|
+
const pathsToProcess = [...state.pathsArray];
|
|
327
|
+
pathsToProcess.forEach(path => {
|
|
353
328
|
// Skip if path contains deleted folder
|
|
354
329
|
if (path.includes(deletedFolderId)) {
|
|
355
330
|
return;
|
|
@@ -363,40 +338,36 @@ function createNavigationStore(instanceId) {
|
|
|
363
338
|
// Clear the temporary array
|
|
364
339
|
pathsToProcess.length = 0;
|
|
365
340
|
// Determine the new current index
|
|
366
|
-
|
|
341
|
+
let newCurrentIndex;
|
|
367
342
|
if (currentPathContainsDeletedFolder) {
|
|
368
343
|
// If current path contained the deleted folder, find its parent path
|
|
369
|
-
|
|
370
|
-
|
|
344
|
+
const deletedFolderIndex = currentPath.indexOf(deletedFolderId);
|
|
345
|
+
const parentPath = deletedFolderIndex > 0
|
|
371
346
|
? currentPath.slice(0, deletedFolderIndex)
|
|
372
347
|
: [];
|
|
373
348
|
// Find the parent path in the new paths array
|
|
374
|
-
|
|
375
|
-
return arePathsEqual(path, parentPath_1);
|
|
376
|
-
});
|
|
349
|
+
const parentPathIndex = newPaths.findIndex(path => arePathsEqual(path, parentPath));
|
|
377
350
|
// Use parent path if found, otherwise use root (first path)
|
|
378
351
|
newCurrentIndex = parentPathIndex >= 0 ? parentPathIndex : 0;
|
|
379
352
|
if (showLogs)
|
|
380
353
|
console.log('Current path contained deleted folder, navigating to parent:', {
|
|
381
|
-
parentPath
|
|
382
|
-
parentPathIndex
|
|
383
|
-
newCurrentIndex
|
|
354
|
+
parentPath,
|
|
355
|
+
parentPathIndex,
|
|
356
|
+
newCurrentIndex
|
|
384
357
|
});
|
|
385
358
|
}
|
|
386
359
|
else {
|
|
387
360
|
// Current path didn't contain deleted folder, try to maintain it
|
|
388
|
-
|
|
389
|
-
return arePathsEqual(path, currentPath);
|
|
390
|
-
});
|
|
361
|
+
const currentPathIndex = newPaths.findIndex(path => arePathsEqual(path, currentPath));
|
|
391
362
|
// Use current path if found, otherwise use the last path
|
|
392
363
|
newCurrentIndex = currentPathIndex >= 0
|
|
393
364
|
? currentPathIndex
|
|
394
365
|
: (isCurrentPathRoot ? 0 : newPaths.length - 1);
|
|
395
366
|
if (showLogs)
|
|
396
367
|
console.log('Maintaining current path after deletion:', {
|
|
397
|
-
currentPathIndex
|
|
398
|
-
newCurrentIndex
|
|
399
|
-
isCurrentPathRoot
|
|
368
|
+
currentPathIndex,
|
|
369
|
+
newCurrentIndex,
|
|
370
|
+
isCurrentPathRoot
|
|
400
371
|
});
|
|
401
372
|
}
|
|
402
373
|
// Ensure we always have at least the root path
|
|
@@ -406,7 +377,7 @@ function createNavigationStore(instanceId) {
|
|
|
406
377
|
if (showLogs)
|
|
407
378
|
console.log('No valid paths remain, resetting to root');
|
|
408
379
|
}
|
|
409
|
-
|
|
380
|
+
const newState = {
|
|
410
381
|
pathsArray: newPaths,
|
|
411
382
|
currentIndex: newCurrentIndex
|
|
412
383
|
};
|
|
@@ -419,9 +390,8 @@ function createNavigationStore(instanceId) {
|
|
|
419
390
|
saveNavigationStateToStorage(instanceId, newState);
|
|
420
391
|
if (browser && shouldPersistFolderPath(instanceId)) {
|
|
421
392
|
try {
|
|
422
|
-
for (
|
|
423
|
-
|
|
424
|
-
if (key.startsWith("".concat(STORAGE_KEY, "-"))) {
|
|
393
|
+
for (const key of Object.keys(localStorage)) {
|
|
394
|
+
if (key.startsWith(`${STORAGE_KEY}-`)) {
|
|
425
395
|
localStorage.removeItem(key);
|
|
426
396
|
}
|
|
427
397
|
}
|
|
@@ -433,27 +403,28 @@ function createNavigationStore(instanceId) {
|
|
|
433
403
|
return newState;
|
|
434
404
|
});
|
|
435
405
|
},
|
|
436
|
-
updateMovedFolderPaths:
|
|
437
|
-
update(
|
|
406
|
+
updateMovedFolderPaths: (movedFolderId, newParentPath) => {
|
|
407
|
+
update(state => {
|
|
438
408
|
if (showLogs)
|
|
439
409
|
console.log('Updating paths for moved folder:', {
|
|
440
|
-
movedFolderId
|
|
441
|
-
newParentPath
|
|
410
|
+
movedFolderId,
|
|
411
|
+
newParentPath,
|
|
442
412
|
currentPaths: state.pathsArray
|
|
443
413
|
});
|
|
444
414
|
// Update paths that contain the moved folder
|
|
445
|
-
|
|
415
|
+
const updatedPaths = state.pathsArray.map(path => {
|
|
446
416
|
// Find if this path contains the moved folder
|
|
447
|
-
|
|
417
|
+
const movedFolderIndex = path.indexOf(movedFolderId);
|
|
448
418
|
if (movedFolderIndex !== -1) {
|
|
449
419
|
// If this path contains the moved folder:
|
|
450
420
|
// 1. Get any subfolders that were inside the moved folder
|
|
451
|
-
|
|
421
|
+
const subfolders = path.slice(movedFolderIndex + 1);
|
|
452
422
|
// 2. Build the new complete path:
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
423
|
+
const newPath = [
|
|
424
|
+
...newParentPath, // Parent folder path (e.g., ['Onboarding Content'])
|
|
425
|
+
movedFolderId, // The moved folder (e.g., 'Design Process')
|
|
426
|
+
...subfolders // Any subfolders that were inside
|
|
427
|
+
];
|
|
457
428
|
if (showLogs)
|
|
458
429
|
console.log('Updated path:', {
|
|
459
430
|
original: path,
|
|
@@ -461,7 +432,7 @@ function createNavigationStore(instanceId) {
|
|
|
461
432
|
details: {
|
|
462
433
|
parentPath: newParentPath,
|
|
463
434
|
movedFolder: movedFolderId,
|
|
464
|
-
subfolders
|
|
435
|
+
subfolders
|
|
465
436
|
},
|
|
466
437
|
reason: 'Contains moved folder'
|
|
467
438
|
});
|
|
@@ -469,25 +440,21 @@ function createNavigationStore(instanceId) {
|
|
|
469
440
|
}
|
|
470
441
|
if (showLogs)
|
|
471
442
|
console.log('Keeping original path:', {
|
|
472
|
-
path
|
|
443
|
+
path,
|
|
473
444
|
reason: 'Does not contain moved folder'
|
|
474
445
|
});
|
|
475
446
|
return path;
|
|
476
447
|
});
|
|
477
448
|
// Remove any duplicate paths that might have been created
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
return p.length === path.length && p.every(function (id, i) { return id === path[i]; });
|
|
481
|
-
});
|
|
449
|
+
const uniquePaths = updatedPaths.filter((path, index, array) => {
|
|
450
|
+
const firstIndex = array.findIndex(p => p.length === path.length && p.every((id, i) => id === path[i]));
|
|
482
451
|
return index === firstIndex;
|
|
483
452
|
});
|
|
484
453
|
// Find the current path in the new paths array
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
});
|
|
490
|
-
var newState = {
|
|
454
|
+
const currentPath = state.pathsArray[state.currentIndex];
|
|
455
|
+
const newCurrentIndex = uniquePaths.findIndex(path => path.length === currentPath.length &&
|
|
456
|
+
path.every((id, i) => id === currentPath[i]));
|
|
457
|
+
const newState = {
|
|
491
458
|
pathsArray: uniquePaths,
|
|
492
459
|
currentIndex: newCurrentIndex >= 0 ? newCurrentIndex : uniquePaths.length - 1
|
|
493
460
|
};
|
|
@@ -505,26 +472,24 @@ function createNavigationStore(instanceId) {
|
|
|
505
472
|
}
|
|
506
473
|
// Create derived stores for common navigation state
|
|
507
474
|
export function createCurrentPathStore(navigationStore) {
|
|
508
|
-
return derived(navigationStore,
|
|
475
|
+
return derived(navigationStore, $nav => $nav.pathsArray[$nav.currentIndex]);
|
|
509
476
|
}
|
|
510
477
|
export function createCanGoBackStore(navigationStore) {
|
|
511
|
-
return derived(navigationStore,
|
|
478
|
+
return derived(navigationStore, $nav => $nav.currentIndex > 0);
|
|
512
479
|
}
|
|
513
480
|
export function createCanGoForwardStore(navigationStore) {
|
|
514
|
-
return derived(navigationStore,
|
|
481
|
+
return derived(navigationStore, $nav => $nav.currentIndex < $nav.pathsArray.length - 1);
|
|
515
482
|
}
|
|
516
483
|
// Store instances cache
|
|
517
|
-
|
|
518
|
-
export function getNavigationStore(instanceId) {
|
|
519
|
-
if (instanceId === void 0) { instanceId = 'default'; }
|
|
484
|
+
const navigationStores = {};
|
|
485
|
+
export function getNavigationStore(instanceId = 'default') {
|
|
520
486
|
if (!navigationStores[instanceId]) {
|
|
521
487
|
navigationStores[instanceId] = createNavigationStore(instanceId);
|
|
522
488
|
}
|
|
523
489
|
return navigationStores[instanceId];
|
|
524
490
|
}
|
|
525
491
|
export function getStoredState(instanceId) {
|
|
526
|
-
|
|
527
|
-
var STORAGE_KEY = getStorageKey(instanceId);
|
|
492
|
+
const STORAGE_KEY = getStorageKey(instanceId);
|
|
528
493
|
try {
|
|
529
494
|
if (showLogs)
|
|
530
495
|
console.log('Getting stored state for instance:', instanceId);
|
|
@@ -533,13 +498,13 @@ export function getStoredState(instanceId) {
|
|
|
533
498
|
console.log('Not in browser context, skipping localStorage');
|
|
534
499
|
return null;
|
|
535
500
|
}
|
|
536
|
-
|
|
501
|
+
const stored = localStorage.getItem(STORAGE_KEY);
|
|
537
502
|
if (!stored) {
|
|
538
503
|
if (showLogs)
|
|
539
504
|
console.log('No stored state found');
|
|
540
505
|
return null;
|
|
541
506
|
}
|
|
542
|
-
|
|
507
|
+
const state = JSON.parse(stored);
|
|
543
508
|
if (showLogs)
|
|
544
509
|
console.log('Found stored state:', {
|
|
545
510
|
pathsArray: state.pathsArray,
|
|
@@ -548,16 +513,16 @@ export function getStoredState(instanceId) {
|
|
|
548
513
|
});
|
|
549
514
|
// During initialization, always return the stored state without validation
|
|
550
515
|
// We'll validate it later when the file data is loaded
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
516
|
+
const store = get(fileStore);
|
|
517
|
+
const isInitialized = !!(store && store.root && store.root.children);
|
|
518
|
+
const hasData = isInitialized && Array.isArray(store?.root?.children) && store.root.children.length > 0;
|
|
554
519
|
if (showLogs)
|
|
555
520
|
console.log('File store state when retrieving stored path:', {
|
|
556
|
-
isInitialized
|
|
557
|
-
hasData
|
|
558
|
-
hasRoot: !!
|
|
559
|
-
hasChildren: !!
|
|
560
|
-
childrenCount:
|
|
521
|
+
isInitialized,
|
|
522
|
+
hasData,
|
|
523
|
+
hasRoot: !!store?.root,
|
|
524
|
+
hasChildren: !!store?.root?.children,
|
|
525
|
+
childrenCount: store?.root?.children?.length
|
|
561
526
|
});
|
|
562
527
|
if (!isInitialized || !hasData) {
|
|
563
528
|
if (showLogs)
|
|
@@ -565,42 +530,38 @@ export function getStoredState(instanceId) {
|
|
|
565
530
|
return state;
|
|
566
531
|
}
|
|
567
532
|
// Only proceed with validation if the file store is initialized AND has data
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
533
|
+
const currentPath = state.pathsArray[state.currentIndex];
|
|
534
|
+
let currentFolder = store.root;
|
|
535
|
+
let validPath = true;
|
|
536
|
+
for (const folderId of currentPath) {
|
|
572
537
|
if (showLogs)
|
|
573
538
|
console.log('Validating stored path folder:', {
|
|
574
|
-
folderId
|
|
575
|
-
hasChildren: !!
|
|
576
|
-
childrenCount:
|
|
577
|
-
availableFolders:
|
|
539
|
+
folderId,
|
|
540
|
+
hasChildren: !!currentFolder.children,
|
|
541
|
+
childrenCount: currentFolder.children?.length,
|
|
542
|
+
availableFolders: currentFolder.children
|
|
543
|
+
?.filter(child => child.type === 'folder')
|
|
544
|
+
.map(child => ({ id: child.id, name: child.name }))
|
|
578
545
|
});
|
|
579
|
-
if (!
|
|
546
|
+
if (!currentFolder.children) {
|
|
580
547
|
validPath = false;
|
|
581
548
|
if (showLogs)
|
|
582
|
-
console.warn('Stored path folder has no children:',
|
|
583
|
-
|
|
549
|
+
console.warn('Stored path folder has no children:', currentFolder);
|
|
550
|
+
break;
|
|
584
551
|
}
|
|
585
|
-
|
|
552
|
+
const nextFolder = currentFolder.children.find(child => child.id === folderId && child.type === 'folder');
|
|
586
553
|
if (!nextFolder) {
|
|
587
554
|
validPath = false;
|
|
588
555
|
if (showLogs)
|
|
589
556
|
console.warn('Stored path folder not found:', {
|
|
590
557
|
searchedId: folderId,
|
|
591
|
-
availableFolders:
|
|
592
|
-
.filter(
|
|
593
|
-
.map(
|
|
558
|
+
availableFolders: currentFolder.children
|
|
559
|
+
.filter(child => child.type === 'folder')
|
|
560
|
+
.map(child => ({ id: child.id, name: child.name }))
|
|
594
561
|
});
|
|
595
|
-
return "break";
|
|
596
|
-
}
|
|
597
|
-
currentFolder_2 = nextFolder;
|
|
598
|
-
};
|
|
599
|
-
for (var _i = 0, currentPath_2 = currentPath; _i < currentPath_2.length; _i++) {
|
|
600
|
-
var folderId = currentPath_2[_i];
|
|
601
|
-
var state_3 = _loop_3(folderId);
|
|
602
|
-
if (state_3 === "break")
|
|
603
562
|
break;
|
|
563
|
+
}
|
|
564
|
+
currentFolder = nextFolder;
|
|
604
565
|
}
|
|
605
566
|
// If path is invalid, return null to trigger reset to root
|
|
606
567
|
if (!validPath) {
|
|
@@ -624,4 +585,4 @@ export function getStoredState(instanceId) {
|
|
|
624
585
|
}
|
|
625
586
|
}
|
|
626
587
|
// Create a store for persisting navigation history
|
|
627
|
-
export
|
|
588
|
+
export const persistHistory = writable(true);
|