@widgetic/file-browser 0.5.47 → 0.5.48

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