@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.
Files changed (81) hide show
  1. package/dist/actions/dragSelectedToFolder.js +115 -104
  2. package/dist/components/FolderTree.svelte.d.ts +7 -4
  3. package/dist/components/core/FileBrowser.svelte +1 -3
  4. package/dist/components/core/dropzoneClick.js +2 -3
  5. package/dist/components/previews/FilePreview.svelte.d.ts +2 -2
  6. package/dist/config.js +3 -4
  7. package/dist/i18n/context.js +2 -2
  8. package/dist/i18n/errors.js +1 -2
  9. package/dist/i18n/messages.js +2 -2
  10. package/dist/i18n/text.js +2 -2
  11. package/dist/mediaLibrary/capabilities.js +3 -4
  12. package/dist/mediaLibrary/context.js +3 -4
  13. package/dist/mediaLibrary/errors.js +35 -46
  14. package/dist/mediaLibrary/normalize.js +42 -45
  15. package/dist/mediaLibrary/paging.js +45 -100
  16. package/dist/mediaLibrary/resolve.js +95 -214
  17. package/dist/mediaLibrary/treeOps.js +20 -40
  18. package/dist/mediaLibrary/urls.js +10 -12
  19. package/dist/mediaLibrary/widgetic.js +54 -140
  20. package/dist/stores/dragStore.js +1 -1
  21. package/dist/stores/fileStore.d.ts +3 -3
  22. package/dist/stores/fileStore.js +37 -44
  23. package/dist/stores/folderCountStore.js +11 -12
  24. package/dist/stores/missingFilesStore.js +3 -3
  25. package/dist/stores/navigationStore.d.ts +1 -1
  26. package/dist/stores/navigationStore.js +178 -217
  27. package/dist/stores/persistentSelectStore.d.ts +1 -1
  28. package/dist/stores/persistentSelectStore.js +94 -117
  29. package/dist/stores/searchStore.js +1 -1
  30. package/dist/stores/uploadApiStore.js +7 -7
  31. package/dist/stores/viewportStore.js +4 -4
  32. package/dist/types/index.js +1 -0
  33. package/dist/utils/apiConfig.js +9 -9
  34. package/dist/utils/brandKitLibraryTree.js +42 -57
  35. package/dist/utils/dateUtils.js +9 -11
  36. package/dist/utils/dragToFolder/batchMoveResult.js +54 -114
  37. package/dist/utils/dragToFolder/folderDropTarget.js +17 -23
  38. package/dist/utils/dragToFolder/springStep.js +3 -4
  39. package/dist/utils/fileGoneProbe.js +16 -65
  40. package/dist/utils/fileKinds.js +13 -14
  41. package/dist/utils/fileNames.js +7 -7
  42. package/dist/utils/fileOperations.js +332 -440
  43. package/dist/utils/fileTypes.js +14 -19
  44. package/dist/utils/fileUtils.js +31 -85
  45. package/dist/utils/folderUtils.js +4 -5
  46. package/dist/utils/gridLayout.js +7 -7
  47. package/dist/utils/imagePreviewCache.js +15 -26
  48. package/dist/utils/imagePreviewFrame.js +13 -13
  49. package/dist/utils/imagePreviewVisualState.js +4 -5
  50. package/dist/utils/imageTransform.js +14 -27
  51. package/dist/utils/itemMenuCapabilities.js +7 -7
  52. package/dist/utils/libraryTree.js +39 -55
  53. package/dist/utils/pendingUploadDeletes.js +113 -289
  54. package/dist/utils/previewKeys.js +1 -1
  55. package/dist/utils/previewListNavigation.js +11 -13
  56. package/dist/utils/previewNavigation.js +7 -10
  57. package/dist/utils/recentFiles.js +6 -16
  58. package/dist/utils/recentFilesLimit.js +2 -2
  59. package/dist/utils/removeItems.js +29 -61
  60. package/dist/utils/resolveFileUrl.js +6 -6
  61. package/dist/utils/safeText.js +12 -14
  62. package/dist/utils/searchDropdownPhase.js +2 -2
  63. package/dist/utils/searchItems.js +14 -30
  64. package/dist/utils/searchNavigation.js +5 -5
  65. package/dist/utils/uploadAuth.js +36 -111
  66. package/dist/utils/uploadDisplayProgress.js +1 -1
  67. package/dist/utils/uploadLimits.js +66 -138
  68. package/dist/utils/uploadListReconcile.js +11 -24
  69. package/dist/utils/uploadPanelDismiss.js +1 -1
  70. package/dist/utils/uploadPanelProgress.js +4 -4
  71. package/dist/utils/uploadProgressMath.js +11 -13
  72. package/dist/utils/uploadRefusals.js +24 -40
  73. package/dist/utils/uploadResponseMapping.js +8 -9
  74. package/dist/utils/uploadUiHelpers.js +17 -17
  75. package/dist/utils/userUploadsStorage.js +133 -270
  76. package/dist/utils/videoFrame.js +2 -2
  77. package/dist/utils/widgeticDelete.js +30 -103
  78. package/dist/utils/widgeticTusUpload.js +105 -189
  79. package/dist/utils/widgeticUpload.js +62 -130
  80. package/dist/utils/xhrMultipartUpload.js +116 -164
  81. 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
- var browser = typeof window !== 'undefined';
8
+ const browser = typeof window !== 'undefined';
29
9
  // CONSTANTS
30
- var showLogs = false;
10
+ const showLogs = false;
31
11
  // Create a derived store for path names that any component can subscribe to
32
- export var currentPathNames = derived(currentFolder, function ($currentFolder) {
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 var navigationActions = writable({
39
- navigateToPath: function (path) { },
40
- navigateToIndex: function (index) { },
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: function (index) {
47
- var unsubscribe = currentFolder.subscribe(function (currentPath) {
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(function (id, index) { return id === path2[index]; });
40
+ path1.every((id, index) => id === path2[index]);
63
41
  }
64
- export function getStorageKey(instanceId) {
65
- if (instanceId === void 0) { instanceId = 'default'; }
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 var WIDGETIC_EDITOR_FILE_PICKER_INSTANCE_ID = 'widgetic-editor-file-picker';
70
- var persistFolderPathByInstance = {};
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
- if (instanceId === void 0) { instanceId = 'default'; }
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
- var storedState = getStoredState(instanceId);
94
- var initialState = storedState || {
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
- var _a = writable(initialState), subscribe = _a.subscribe, set = _a.set, update = _a.update;
76
+ const { subscribe, set, update } = writable(initialState);
101
77
  // Add a flag to track if we should validate paths
102
- var isFileStoreInitialized = false;
103
- var hasData = false;
78
+ let isFileStoreInitialized = false;
79
+ let hasData = false;
104
80
  // Subscribe to fileStore to know when it's initialized
105
- fileStore.subscribe(function (store) {
106
- var _a, _b, _c, _d;
107
- var wasInitialized = isFileStoreInitialized;
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((_a = store === null || store === void 0 ? void 0 : store.root) === null || _a === void 0 ? void 0 : _a.children) && store.root.children.length > 0;
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: wasInitialized,
88
+ wasInitialized,
114
89
  isNowInitialized: isFileStoreInitialized,
115
- previousHasData: previousHasData,
90
+ previousHasData,
116
91
  nowHasData: hasData,
117
- hasRoot: !!(store === null || store === void 0 ? void 0 : store.root),
118
- hasChildren: !!((_b = store === null || store === void 0 ? void 0 : store.root) === null || _b === void 0 ? void 0 : _b.children),
119
- childrenCount: (_d = (_c = store === null || store === void 0 ? void 0 : store.root) === null || _c === void 0 ? void 0 : _c.children) === null || _d === void 0 ? void 0 : _d.length
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(function (state) {
126
- var currentPath = state.pathsArray[state.currentIndex];
127
- var currentFolder = store.root;
128
- var validPath = true;
129
- var _loop_1 = function (folderId) {
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
- return "break";
107
+ break;
133
108
  }
134
- var nextFolder = currentFolder.children.find(function (child) { return child.id === folderId && child.type === 'folder'; });
109
+ const nextFolder = currentFolder.children.find(child => child.id === folderId && child.type === 'folder');
135
110
  if (!nextFolder) {
136
111
  validPath = false;
137
- return "break";
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
- var rootState = {
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: subscribe,
162
- navigateToFolder: function (newPath, forceNavigation) {
163
- if (forceNavigation === void 0) { forceNavigation = false; }
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
- var currentPath = state.pathsArray[state.currentIndex];
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
- var validPath = true;
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
- var store = get(fileStore);
186
- var currentFolder_1 = store.root;
187
- var _loop_2 = function (folderId) {
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: folderId,
191
- hasChildren: !!currentFolder_1.children,
192
- childrenCount: (_a = currentFolder_1.children) === null || _a === void 0 ? void 0 : _a.length,
193
- availableFolders: (_b = currentFolder_1.children) === null || _b === void 0 ? void 0 : _b.filter(function (child) { return child.type === 'folder'; }).map(function (child) { return ({ id: child.id, name: child.name }); })
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 (!currentFolder_1.children) {
164
+ if (!currentFolder.children) {
196
165
  validPath = false;
197
- console.warn('Folder has no children:', currentFolder_1);
198
- return "break";
166
+ console.warn('Folder has no children:', currentFolder);
167
+ break;
199
168
  }
200
- var nextFolder = currentFolder_1.children.find(function (child) { return child.id === folderId && child.type === 'folder'; });
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: currentFolder_1.children
206
- .filter(function (child) { return child.type === 'folder'; })
207
- .map(function (child) { return ({ id: child.id, name: child.name }); })
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: 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: forceNavigation
196
+ forceNavigation
234
197
  });
235
- var rootState = {
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
- var lastPathIndex = state.pathsArray.length - 1;
246
- var lastPath = lastPathIndex >= 0 ? state.pathsArray[lastPathIndex] : null;
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
- var newState_1 = __assign(__assign({}, state), { currentIndex: lastPathIndex });
260
- saveNavigationStateToStorage(instanceId, newState_1);
261
- return newState_1;
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
- var existingPathIndex = state.pathsArray.findIndex(function (path) { return arePathsEqual(path, newPath); });
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: 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
- var newState_2 = __assign(__assign({}, state), { currentIndex: existingPathIndex });
279
- saveNavigationStateToStorage(instanceId, newState_2);
280
- return newState_2;
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
- var newPathsArray = __spreadArray(__spreadArray([], state.pathsArray.slice(0, state.currentIndex + 1), true), [newPath], false);
285
- var newState = {
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: function () {
300
- update(function (state) {
268
+ navigateBack: () => {
269
+ update(state => {
301
270
  if (state.currentIndex > 0) {
302
- var newState = __assign(__assign({}, state), { currentIndex: state.currentIndex - 1 });
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: function () {
310
- update(function (state) {
281
+ navigateForward: () => {
282
+ update(state => {
311
283
  if (state.currentIndex < state.pathsArray.length - 1) {
312
- var newState = __assign(__assign({}, state), { currentIndex: state.currentIndex + 1 });
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: function () {
320
- var initialState = {
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: function (deletedFolderId) {
335
- update(function (state) {
309
+ cleanupPaths: (deletedFolderId) => {
310
+ update(state => {
336
311
  // Store the current path before cleanup
337
- var currentPath = state.pathsArray[state.currentIndex];
338
- var isCurrentPathRoot = currentPath.length === 0;
339
- var currentPathContainsDeletedFolder = currentPath.includes(deletedFolderId);
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: deletedFolderId,
343
- currentPath: currentPath,
344
- isCurrentPathRoot: isCurrentPathRoot,
345
- currentPathContainsDeletedFolder: 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
- var newPaths = [];
324
+ let newPaths = [];
350
325
  // Clone and cleanup the paths array
351
- var pathsToProcess = __spreadArray([], state.pathsArray, true);
352
- pathsToProcess.forEach(function (path) {
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
- var newCurrentIndex;
341
+ let newCurrentIndex;
367
342
  if (currentPathContainsDeletedFolder) {
368
343
  // If current path contained the deleted folder, find its parent path
369
- var deletedFolderIndex = currentPath.indexOf(deletedFolderId);
370
- var parentPath_1 = deletedFolderIndex > 0
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
- var parentPathIndex = newPaths.findIndex(function (path) {
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: parentPath_1,
382
- parentPathIndex: parentPathIndex,
383
- newCurrentIndex: 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
- var currentPathIndex = newPaths.findIndex(function (path) {
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: currentPathIndex,
398
- newCurrentIndex: newCurrentIndex,
399
- isCurrentPathRoot: 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
- var newState = {
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 (var _i = 0, _a = Object.keys(localStorage); _i < _a.length; _i++) {
423
- var key = _a[_i];
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: function (movedFolderId, newParentPath) {
437
- update(function (state) {
406
+ updateMovedFolderPaths: (movedFolderId, newParentPath) => {
407
+ update(state => {
438
408
  if (showLogs)
439
409
  console.log('Updating paths for moved folder:', {
440
- movedFolderId: movedFolderId,
441
- newParentPath: newParentPath,
410
+ movedFolderId,
411
+ newParentPath,
442
412
  currentPaths: state.pathsArray
443
413
  });
444
414
  // Update paths that contain the moved folder
445
- var updatedPaths = state.pathsArray.map(function (path) {
415
+ const updatedPaths = state.pathsArray.map(path => {
446
416
  // Find if this path contains the moved folder
447
- var movedFolderIndex = path.indexOf(movedFolderId);
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
- var subfolders = path.slice(movedFolderIndex + 1);
421
+ const subfolders = path.slice(movedFolderIndex + 1);
452
422
  // 2. Build the new complete path:
453
- var newPath = __spreadArray(__spreadArray(__spreadArray([], newParentPath, true), [
454
- movedFolderId
455
- ], false), subfolders // Any subfolders that were inside
456
- , true);
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: 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: 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
- var uniquePaths = updatedPaths.filter(function (path, index, array) {
479
- var firstIndex = array.findIndex(function (p) {
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
- var currentPath = state.pathsArray[state.currentIndex];
486
- var newCurrentIndex = uniquePaths.findIndex(function (path) {
487
- return path.length === currentPath.length &&
488
- path.every(function (id, i) { return id === currentPath[i]; });
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, function ($nav) { return $nav.pathsArray[$nav.currentIndex]; });
475
+ return derived(navigationStore, $nav => $nav.pathsArray[$nav.currentIndex]);
509
476
  }
510
477
  export function createCanGoBackStore(navigationStore) {
511
- return derived(navigationStore, function ($nav) { return $nav.currentIndex > 0; });
478
+ return derived(navigationStore, $nav => $nav.currentIndex > 0);
512
479
  }
513
480
  export function createCanGoForwardStore(navigationStore) {
514
- return derived(navigationStore, function ($nav) { return $nav.currentIndex < $nav.pathsArray.length - 1; });
481
+ return derived(navigationStore, $nav => $nav.currentIndex < $nav.pathsArray.length - 1);
515
482
  }
516
483
  // Store instances cache
517
- var navigationStores = {};
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
- var _a, _b, _c, _d, _e, _f;
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
- var stored = localStorage.getItem(STORAGE_KEY);
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
- var state = JSON.parse(stored);
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
- var store = get(fileStore);
552
- var isInitialized = !!(store && store.root && store.root.children);
553
- var hasData = isInitialized && Array.isArray((_a = store === null || store === void 0 ? void 0 : store.root) === null || _a === void 0 ? void 0 : _a.children) && store.root.children.length > 0;
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: isInitialized,
557
- hasData: hasData,
558
- hasRoot: !!(store === null || store === void 0 ? void 0 : store.root),
559
- hasChildren: !!((_b = store === null || store === void 0 ? void 0 : store.root) === null || _b === void 0 ? void 0 : _b.children),
560
- childrenCount: (_d = (_c = store === null || store === void 0 ? void 0 : store.root) === null || _c === void 0 ? void 0 : _c.children) === null || _d === void 0 ? void 0 : _d.length
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
- var currentPath = state.pathsArray[state.currentIndex];
569
- var currentFolder_2 = store.root;
570
- var validPath = true;
571
- var _loop_3 = function (folderId) {
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: folderId,
575
- hasChildren: !!currentFolder_2.children,
576
- childrenCount: (_e = currentFolder_2.children) === null || _e === void 0 ? void 0 : _e.length,
577
- availableFolders: (_f = currentFolder_2.children) === null || _f === void 0 ? void 0 : _f.filter(function (child) { return child.type === 'folder'; }).map(function (child) { return ({ id: child.id, name: child.name }); })
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 (!currentFolder_2.children) {
546
+ if (!currentFolder.children) {
580
547
  validPath = false;
581
548
  if (showLogs)
582
- console.warn('Stored path folder has no children:', currentFolder_2);
583
- return "break";
549
+ console.warn('Stored path folder has no children:', currentFolder);
550
+ break;
584
551
  }
585
- var nextFolder = currentFolder_2.children.find(function (child) { return child.id === folderId && child.type === 'folder'; });
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: currentFolder_2.children
592
- .filter(function (child) { return child.type === 'folder'; })
593
- .map(function (child) { return ({ id: child.id, name: child.name }); })
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 var persistHistory = writable(true);
588
+ export const persistHistory = writable(true);