@widgetic/file-browser 0.5.40 → 0.5.42

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 (59) hide show
  1. package/dist/components/core/FileBrowser.svelte +157 -62
  2. package/dist/components/core/FileBrowser.svelte.d.ts +5 -1
  3. package/dist/components/core/FileUploader.svelte +49 -15
  4. package/dist/components/core/RecentFiles.svelte +23 -11
  5. package/dist/components/core/RecentFiles.svelte.d.ts +1 -0
  6. package/dist/components/core/SearchDropdown.svelte +124 -26
  7. package/dist/components/core/UploadPanel.svelte +1 -1
  8. package/dist/components/items/FileItem.svelte +12 -2
  9. package/dist/components/items/FolderItem.svelte +8 -1
  10. package/dist/components/modals/index.d.ts +0 -1
  11. package/dist/components/modals/index.js +0 -1
  12. package/dist/components/previews/FilePreview.svelte +226 -35
  13. package/dist/components/previews/FilePreview.svelte.d.ts +7 -3
  14. package/dist/components/previews/FontPreview.svelte +4 -1
  15. package/dist/components/previews/FontPreview.svelte.d.ts +2 -0
  16. package/dist/components/previews/ImagePreview.svelte +60 -31
  17. package/dist/components/previews/ImagePreview.svelte.d.ts +3 -0
  18. package/dist/components/previews/PreviewHeaderBar.svelte +33 -25
  19. package/dist/components/previews/PreviewHeaderBar.svelte.d.ts +2 -0
  20. package/dist/components/ui/DragSelect.svelte +85 -67
  21. package/dist/components/ui/DragSelect.svelte.d.ts +1 -0
  22. package/dist/data/demoContent.json +13 -11
  23. package/dist/i18n/messages.d.ts +0 -1
  24. package/dist/i18n/messages.js +0 -1
  25. package/dist/index.d.ts +3 -0
  26. package/dist/index.js +3 -0
  27. package/dist/stores/navigationStore.d.ts +5 -0
  28. package/dist/stores/navigationStore.js +40 -67
  29. package/dist/utils/escapeSelectionAction.d.ts +18 -0
  30. package/dist/utils/escapeSelectionAction.js +18 -0
  31. package/dist/utils/imagePreviewCache.d.ts +16 -0
  32. package/dist/utils/imagePreviewCache.js +78 -0
  33. package/dist/utils/imagePreviewVisualState.d.ts +19 -0
  34. package/dist/utils/imagePreviewVisualState.js +22 -0
  35. package/dist/utils/menuKeydownBubble.d.ts +9 -0
  36. package/dist/utils/menuKeydownBubble.js +11 -0
  37. package/dist/utils/previewNavigation.d.ts +4 -0
  38. package/dist/utils/previewNavigation.js +17 -0
  39. package/dist/utils/recentFiles.d.ts +6 -0
  40. package/dist/utils/recentFiles.js +21 -0
  41. package/dist/utils/recentFilesLimit.d.ts +8 -0
  42. package/dist/utils/recentFilesLimit.js +17 -0
  43. package/dist/utils/searchEscapeAction.d.ts +10 -0
  44. package/dist/utils/searchEscapeAction.js +12 -0
  45. package/dist/utils/searchItems.d.ts +2 -4
  46. package/dist/utils/searchItems.js +12 -5
  47. package/dist/utils/searchNavigation.d.ts +12 -0
  48. package/dist/utils/searchNavigation.js +42 -0
  49. package/dist/utils/uploadDisplayProgress.d.ts +4 -0
  50. package/dist/utils/uploadDisplayProgress.js +9 -0
  51. package/dist/utils/uploadListReconcile.d.ts +11 -0
  52. package/dist/utils/uploadListReconcile.js +30 -0
  53. package/dist/utils/uploadPanelProgress.d.ts +5 -0
  54. package/dist/utils/uploadPanelProgress.js +17 -0
  55. package/dist/utils/userUploadsStorage.d.ts +8 -0
  56. package/dist/utils/userUploadsStorage.js +32 -0
  57. package/package.json +3 -3
  58. package/dist/components/modals/SearchModal.svelte +0 -296
  59. package/dist/components/modals/SearchModal.svelte.d.ts +0 -27
@@ -16,9 +16,13 @@
16
16
  export let meta = '';
17
17
  export let showMeta = true;
18
18
  export let allowSelecting = false;
19
+ /** When true, the preview shows the picker Select control (editor embed mode). */
20
+ export let showSelectInPreview = false;
19
21
  export let isSelected = false;
20
22
  export let canGoPrevious = false;
21
23
  export let canGoNext = false;
24
+ /** When false, previous/next controls are not shown (single item in folder). */
25
+ export let showNavigation = true;
22
26
  // What a screen reader says for the close button
23
27
  export let closeLabel = '';
24
28
  </script>
@@ -35,32 +39,36 @@
35
39
  {/if}
36
40
  </div>
37
41
 
38
- {#if allowSelecting}
42
+ {#if allowSelecting && (showNavigation || showSelectInPreview)}
39
43
  <div class="flex shrink-0 items-center gap-1">
40
- <IconButton
41
- variant="ghost"
42
- label={$t('preview.previousFile')}
43
- disabled={!canGoPrevious}
44
- onclick={() => dispatch('previous')}
45
- >
46
- <IconChevronLeft class="size-4 stroke-2 rtl:rotate-180" />
47
- </IconButton>
48
- <IconButton
49
- variant="ghost"
50
- label={$t('preview.nextFile')}
51
- disabled={!canGoNext}
52
- onclick={() => dispatch('next')}
53
- >
54
- <IconChevronRight class="size-4 stroke-2 rtl:rotate-180" />
55
- </IconButton>
56
- <Button
57
- variant="outline"
58
- size="sm"
59
- class="press-feedback"
60
- onclick={() => dispatch('select')}
61
- >
62
- {isSelected ? $t('action.selected') : $t('action.select')}
63
- </Button>
44
+ {#if showNavigation}
45
+ <IconButton
46
+ variant="ghost"
47
+ label={$t('preview.previousFile')}
48
+ disabled={!canGoPrevious}
49
+ onclick={() => dispatch('previous')}
50
+ >
51
+ <IconChevronLeft class="size-4 stroke-2 rtl:rotate-180" />
52
+ </IconButton>
53
+ <IconButton
54
+ variant="ghost"
55
+ label={$t('preview.nextFile')}
56
+ disabled={!canGoNext}
57
+ onclick={() => dispatch('next')}
58
+ >
59
+ <IconChevronRight class="size-4 stroke-2 rtl:rotate-180" />
60
+ </IconButton>
61
+ {/if}
62
+ {#if showSelectInPreview}
63
+ <Button
64
+ variant="outline"
65
+ size="sm"
66
+ class="press-feedback"
67
+ onclick={() => dispatch('select')}
68
+ >
69
+ {isSelected ? $t('action.selected') : $t('action.select')}
70
+ </Button>
71
+ {/if}
64
72
  </div>
65
73
  {/if}
66
74
 
@@ -16,9 +16,11 @@ declare const PreviewHeaderBar: $$__sveltets_2_IsomorphicComponent<{
16
16
  meta?: string;
17
17
  showMeta?: boolean;
18
18
  allowSelecting?: boolean;
19
+ /** When true, the preview shows the picker Select control (editor embed mode). */ showSelectInPreview?: boolean;
19
20
  isSelected?: boolean;
20
21
  canGoPrevious?: boolean;
21
22
  canGoNext?: boolean;
23
+ /** When false, previous/next controls are not shown (single item in folder). */ showNavigation?: boolean;
22
24
  closeLabel?: string;
23
25
  }, {
24
26
  previous: CustomEvent<void>;
@@ -18,11 +18,17 @@
18
18
 
19
19
  let selectionBox: HTMLDivElement;
20
20
  let isDragging = false;
21
+ /** Parent reads whether a rubber-band drag is active (Escape cancels the drag, not the selection). */
22
+ export let dragBandActive = false;
23
+ $: dragBandActive = isDragging;
21
24
  let startX = 0;
22
25
  let startY = 0;
23
26
  let currentX = 0;
24
27
  let currentY = 0;
25
28
  let scrollStartY = 0;
29
+ /** Where the pointer is in the viewport: the auto-scroll reads it while the pointer rests and the list moves under it. */
30
+ let lastPointerClientX = 0;
31
+ let lastPointerClientY = 0;
26
32
  let autoScrollInterval: number | null = null;
27
33
  let selectedItemIds = new Set<string>();
28
34
  let cleanup: (() => void) | null = null;
@@ -47,6 +53,12 @@
47
53
  return element.getAttribute('data-selected') === 'true';
48
54
  }
49
55
 
56
+ function clearDragHoverMarkup(element: Element) {
57
+ element.classList.remove('hover-effect');
58
+ element.classList.remove('recent-file-selected');
59
+ element.removeAttribute('data-drag-hover');
60
+ }
61
+
50
62
  function cacheItems() {
51
63
  if (!container) return;
52
64
  const alreadySelectedInStore = persistentSelectStore.getSelected(currentFilter);
@@ -119,6 +131,7 @@
119
131
 
120
132
  function handleKeyDown(e: KeyboardEvent) {
121
133
  if (e.key === 'Escape' && isDragging) {
134
+ e.stopPropagation();
122
135
  mouseIsDown = false;
123
136
  isDragging = false;
124
137
 
@@ -128,9 +141,7 @@
128
141
 
129
142
  stopAutoScroll();
130
143
 
131
- container.querySelectorAll('.hover-effect').forEach(element => {
132
- element.classList.remove('hover-effect');
133
- });
144
+ container.querySelectorAll('.hover-effect').forEach(clearDragHoverMarkup);
134
145
 
135
146
  hasMovedEnough = false;
136
147
  startItemId = null;
@@ -209,15 +220,17 @@
209
220
  .filter((id): id is string => id !== null)
210
221
  );
211
222
 
212
- scrollStartY = container.scrollTop || 0;
213
-
214
- const scrollRect = scrollContainer?.getBoundingClientRect() || container.getBoundingClientRect();
215
-
216
- startX = e.clientX - scrollRect.left;
217
- startY = e.clientY - scrollRect.top;
223
+ scrollStartY = getScrollableElement()?.scrollTop || container.scrollTop || 0;
224
+
225
+ const containerRect = container.getBoundingClientRect();
226
+
227
+ startX = e.clientX - containerRect.left;
228
+ startY = e.clientY - containerRect.top;
218
229
 
219
230
  currentX = startX;
220
231
  currentY = startY;
232
+ lastPointerClientX = e.clientX;
233
+ lastPointerClientY = e.clientY;
221
234
  };
222
235
 
223
236
  const handleMouseMove = (e: MouseEvent) => {
@@ -230,10 +243,12 @@
230
243
  e.preventDefault();
231
244
  e.stopPropagation();
232
245
 
233
- const scrollRect = scrollContainer?.getBoundingClientRect() || container.getBoundingClientRect();
234
-
235
- currentX = e.clientX - scrollRect.left;
236
- currentY = e.clientY - scrollRect.top;
246
+ const containerRect = container.getBoundingClientRect();
247
+
248
+ currentX = e.clientX - containerRect.left;
249
+ currentY = e.clientY - containerRect.top;
250
+ lastPointerClientX = e.clientX;
251
+ lastPointerClientY = e.clientY;
237
252
 
238
253
  if (scrollContainer) {
239
254
  const bounds = scrollContainer.getBoundingClientRect();
@@ -317,10 +332,7 @@
317
332
  resetSelectionBox();
318
333
  stopAutoScroll();
319
334
 
320
- container.querySelectorAll('.hover-effect').forEach(element => {
321
- element.classList.remove('hover-effect');
322
- element.classList.remove('recent-file-selected');
323
- });
335
+ container.querySelectorAll('.hover-effect').forEach(clearDragHoverMarkup);
324
336
 
325
337
  hasMovedEnough = false;
326
338
  startItemId = null;
@@ -403,15 +415,14 @@
403
415
  });
404
416
  }
405
417
 
406
- container.querySelectorAll('.hover-effect').forEach(element => {
407
- element.classList.remove('hover-effect');
408
-
418
+ container.querySelectorAll('.hover-effect').forEach((element) => {
409
419
  const itemId = element.getAttribute('data-item-id');
410
- const isAlreadySelected = isItemSelectedInDom(element as HTMLElement) ||
411
- (itemId && alreadySelectedInStore.includes(itemId));
412
-
413
- if (!isAlreadySelected) {
414
- element.classList.remove('recent-file-selected');
420
+ const isAlreadySelected =
421
+ isItemSelectedInDom(element as HTMLElement) ||
422
+ (itemId != null && alreadySelectedInStore.includes(itemId));
423
+ clearDragHoverMarkup(element);
424
+ if (isAlreadySelected && element instanceof HTMLElement) {
425
+ element.setAttribute('data-selected', 'true');
415
426
  }
416
427
  });
417
428
 
@@ -478,19 +489,13 @@
478
489
  let width = Math.abs(currentX - startX);
479
490
  let height = Math.abs(currentY - startY);
480
491
 
481
- if (scrollContainer) {
482
- const scrollRect = scrollContainer.getBoundingClientRect();
483
-
484
- const scrollLeft = 0;
485
- const scrollTop = 0;
486
- const scrollRight = scrollRect.width;
487
- const scrollBottom = scrollRect.height;
488
-
489
- left = Math.max(left, scrollLeft);
490
- top = Math.max(top, scrollTop);
491
- width = Math.min(width, scrollRight - left);
492
- height = Math.min(height, scrollBottom - top);
493
- }
492
+ // Clamp within the content container (grid + recent), not only the scroll viewport.
493
+ const maxWidth = container.clientWidth;
494
+ const maxHeight = container.clientHeight;
495
+ left = Math.max(left, 0);
496
+ top = Math.max(top, 0);
497
+ width = Math.min(width, maxWidth - left);
498
+ height = Math.min(height, maxHeight - top);
494
499
 
495
500
  selectionBox.style.display = 'block';
496
501
  // rtl-ok: rubber-band box between two pointer positions in the scroll container's coordinate space
@@ -525,50 +530,73 @@
525
530
  const isMarked = intersectsSelection || item.isSelectedInStore || item.isSelectedInDom;
526
531
 
527
532
  if (isMarked) {
528
- if (!selectedItemIds.has(item.id)) {
533
+ if (!item.element.classList.contains('hover-effect')) {
529
534
  selectedItemIds.add(item.id);
530
535
  item.element.classList.add('hover-effect');
536
+ item.element.setAttribute('data-drag-hover', 'true');
531
537
  if (item.isInRecentFiles) {
532
538
  item.element.classList.add('recent-file-selected');
533
539
  }
534
540
  }
535
- } else {
536
- if (!initiallySelectedItems.has(item.id) && !item.isSelectedInStore && !item.isSelectedInDom) {
537
- if (selectedItemIds.has(item.id)) {
538
- selectedItemIds.delete(item.id);
539
- item.element.classList.remove('hover-effect');
540
- item.element.classList.remove('recent-file-selected');
541
- }
541
+ } else if (
542
+ !initiallySelectedItems.has(item.id) &&
543
+ !item.isSelectedInStore &&
544
+ !item.isSelectedInDom
545
+ ) {
546
+ if (item.element.classList.contains('hover-effect')) {
547
+ selectedItemIds.delete(item.id);
548
+ clearDragHoverMarkup(item.element);
542
549
  }
543
550
  }
544
551
  }
545
552
  }
546
553
 
554
+ /**
555
+ * The element that really scrolls. `scrollContainer` is the root of the scroll area, which never scrolls itself:
556
+ * the list moves inside the viewport element in it, so writing `scrollTop` on the root did nothing and the drag
557
+ * could not reach files below the fold (the recent files) at all.
558
+ */
559
+ function getScrollableElement(): HTMLElement | null {
560
+ if (!scrollContainer) return null;
561
+ return scrollContainer.querySelector<HTMLElement>('[data-scroll-area-viewport]') ?? scrollContainer;
562
+ }
563
+
547
564
  function startAutoScroll() {
548
565
  if (!scrollContainer) return;
549
566
 
550
- stopAutoScroll();
567
+ // Already running: it reads the pointer from lastPointerClientX/Y on every tick, so every pointer move restarting
568
+ // it only kept it from ever firing while the pointer moved.
569
+ if (autoScrollInterval !== null) return;
551
570
 
552
571
  autoScrollInterval = window.setInterval(() => {
553
- if (!isDragging || !scrollContainer || !container) return;
572
+ const scrollableElement = getScrollableElement();
573
+ if (!isDragging || !scrollContainer || !scrollableElement || !container) return;
554
574
 
555
- const containerRect = scrollContainer.getBoundingClientRect();
556
- const mouseY = currentY + container.getBoundingClientRect().top - (scrollContainer?.scrollTop || 0);
557
-
558
- const distanceFromTop = mouseY - containerRect.top;
559
- const distanceFromBottom = containerRect.bottom - mouseY;
575
+ // The pointer is read in the viewport (where the user holds it), not rebuilt from the box coordinates: those move
576
+ // with the content, so after the first few steps of scrolling they put the pointer in the wrong place and the
577
+ // list stopped scrolling long before the recent files were reached.
578
+ const scrollRect = scrollContainer.getBoundingClientRect();
579
+ const distanceFromTop = lastPointerClientY - scrollRect.top;
580
+ const distanceFromBottom = scrollRect.bottom - lastPointerClientY;
560
581
 
561
582
  let scrolled = false;
562
583
 
563
584
  if (distanceFromTop < SCROLL_THRESHOLD) {
564
- scrollContainer.scrollTop -= SCROLL_SPEED;
565
- scrolled = true;
585
+ const previousScrollTop = scrollableElement.scrollTop;
586
+ scrollableElement.scrollTop -= SCROLL_SPEED;
587
+ scrolled = scrollableElement.scrollTop !== previousScrollTop;
566
588
  } else if (distanceFromBottom < SCROLL_THRESHOLD) {
567
- scrollContainer.scrollTop += SCROLL_SPEED;
568
- scrolled = true;
589
+ const previousScrollTop = scrollableElement.scrollTop;
590
+ scrollableElement.scrollTop += SCROLL_SPEED;
591
+ scrolled = scrollableElement.scrollTop !== previousScrollTop;
569
592
  }
570
593
 
571
594
  if (scrolled) {
595
+ // The content moved under a resting pointer: the box grows to where the pointer now is in the content.
596
+ const containerRect = container.getBoundingClientRect();
597
+ currentX = lastPointerClientX - containerRect.left;
598
+ currentY = lastPointerClientY - containerRect.top;
599
+ updateSelectionBox();
572
600
  cacheItems();
573
601
  checkIntersections();
574
602
  }
@@ -592,16 +620,6 @@
592
620
  {/if}
593
621
 
594
622
  <style>
595
- :global(.hover-effect > *) {
596
- background-color: var(--accent) !important;
597
- border-radius: var(--radius-xl) !important;
598
- }
599
-
600
- :global(.recent-file-selected.hover-effect > *) {
601
- background-color: var(--brand-subtle) !important;
602
- box-shadow: inset 0 0 0 1px var(--brand) !important;
603
- }
604
-
605
623
  :global(.modal-content-inner-container),
606
624
  :global(.base-modal-portal),
607
625
  :global(.modal-content-root-container),
@@ -19,6 +19,7 @@ declare const DragSelect: $$__sveltets_2_IsomorphicComponent<{
19
19
  items?: FileSystemItem[];
20
20
  scrollContainer?: HTMLElement | null;
21
21
  currentFilter?: FileFilterType;
22
+ /** Parent reads whether a rubber-band drag is active (Escape cancels the drag, not the selection). */ dragBandActive?: boolean;
22
23
  }, {
23
24
  select: CustomEvent<{
24
25
  added: FileSystemItem[];
@@ -477,13 +477,15 @@
477
477
  },
478
478
  {
479
479
  "id": "file_pqr844",
480
- "name": "celebration.mp4",
480
+ "name": "image 30.jpg",
481
481
  "type": "file",
482
- "size": 150000000,
482
+ "size": 2400000,
483
+ "width": 1024,
484
+ "height": 683,
483
485
  "modified": "2023-09-24T16:30:00Z",
484
- "url": "video/video-file.mp4",
485
- "thumbnail": "video/video-file.png",
486
- "hash": "AE F7 09 06 80 A6 F9 6B 8B 88 76 AE 77 72 76 98 76 99 AE 8D D0 A9 08"
486
+ "url": "image/image 30.jpg",
487
+ "thumbnail": "thumbnail/image 30.jpg",
488
+ "hash": "C4 B7 05 05 80 F5 1A C7 7E 76 89 83 83 8C A6 86 05 71 7A 12 F8"
487
489
  },
488
490
  {
489
491
  "id": "folder_stu910",
@@ -1156,15 +1158,15 @@
1156
1158
  },
1157
1159
  {
1158
1160
  "id": "file_stu364",
1159
- "name": "image 28.jpg",
1161
+ "name": "image 29.jpg",
1160
1162
  "type": "file",
1161
- "size": 3150000,
1163
+ "size": 3050000,
1162
1164
  "width": 1024,
1163
1165
  "height": 683,
1164
- "modified": "2024-09-27T11:45:00Z",
1165
- "url": "image/image 28.jpg",
1166
- "thumbnail": "thumbnail/image 28.jpg",
1167
- "hash": "55 38 06 15 86 72 96 58 9F 56 A5 49 B7 C6 46 94 FA 9B BC AF C9"
1166
+ "modified": "2024-09-27T11:50:00Z",
1167
+ "url": "image/image 29.jpg",
1168
+ "thumbnail": "thumbnail/image 29.jpg",
1169
+ "hash": "E2 B7 05 05 80 F5 1A C7 7E 76 89 83 83 8C A6 86 05 71 7A 12 F9"
1168
1170
  }
1169
1171
  ]
1170
1172
  }
@@ -230,7 +230,6 @@ export declare const FILE_BROWSER_MESSAGES: {
230
230
  readonly 'selectedFiles.count': "{count, plural, one {# file selected} other {# files selected}}";
231
231
  readonly 'selectedFiles.confirmMany': "{count, plural, one {Use # file} other {Use # files}}";
232
232
  readonly 'selectedFiles.remove': "Remove from selection";
233
- readonly 'searchModal.placeholder': "Search files and folders…";
234
233
  readonly 'searchModal.jumpToFolder': "Jump to folder";
235
234
  readonly 'searchModal.empty': "No files found";
236
235
  readonly 'searchModal.clearQuery': "Clear search";
@@ -242,7 +242,6 @@ export const FILE_BROWSER_MESSAGES = {
242
242
  'selectedFiles.confirmMany': '{count, plural, one {Use # file} other {Use # files}}',
243
243
  'selectedFiles.remove': 'Remove from selection',
244
244
  // ===== Search window =====
245
- 'searchModal.placeholder': 'Search files and folders…',
246
245
  'searchModal.jumpToFolder': 'Jump to folder',
247
246
  'searchModal.empty': 'No files found',
248
247
  'searchModal.clearQuery': 'Clear search',
package/dist/index.d.ts CHANGED
@@ -3,6 +3,9 @@ export * from './components';
3
3
  export * from './stores';
4
4
  export { fileBrowserUploadConfig, setFileBrowserUploadConfig, getFileBrowserUploadConfig, type FileBrowserUploadConfig, } from './stores/uploadApiStore';
5
5
  export * from './utils';
6
+ export { fetchUserUploadsFromApi } from './utils/widgeticUpload';
7
+ export { mergeRemoteUploadList, WIDGETIC_UPLOADS_LIST_LIMIT } from './utils/uploadListReconcile';
8
+ export { removePersistedUploads, replacePersistedUploads } from './utils/userUploadsStorage';
6
9
  export type { MediaLibraryCapabilities, MediaLibraryDeleteRequest, MediaLibraryErrorCode, MediaLibraryFile, MediaLibraryListRequest, MediaLibraryPage, MediaLibraryProvider, MediaLibraryRenameRequest, MediaLibraryUploadRequest, WidgeticMediaLibraryOptions, } from './mediaLibrary';
7
10
  export { MediaLibraryError, createWidgeticMediaLibrary } from './mediaLibrary';
8
11
  export { FILE_BROWSER_MESSAGES, checkFileBrowserMessages, describeMessageProblem, type FileBrowserMessageKey, type MessageOverrides, type MessageProblem, } from './i18n';
package/dist/index.js CHANGED
@@ -7,6 +7,9 @@ export * from './stores';
7
7
  export { fileBrowserUploadConfig, setFileBrowserUploadConfig, getFileBrowserUploadConfig, } from './stores/uploadApiStore';
8
8
  // Export all utilities
9
9
  export * from './utils';
10
+ export { fetchUserUploadsFromApi } from './utils/widgeticUpload';
11
+ export { mergeRemoteUploadList, WIDGETIC_UPLOADS_LIST_LIMIT } from './utils/uploadListReconcile';
12
+ export { removePersistedUploads, replacePersistedUploads } from './utils/userUploadsStorage';
10
13
  export { MediaLibraryError, createWidgeticMediaLibrary } from './mediaLibrary';
11
14
  // Export the languages seam: the English catalog (every key a page can replace through `messages`), and the checker
12
15
  // a page or a build step can run on its own messages.
@@ -11,6 +11,11 @@ export type NavigationState = {
11
11
  currentIndex: number;
12
12
  };
13
13
  export declare function getStorageKey(instanceId?: string): string;
14
+ /** Shared localStorage id for file pickers inside the Widgetic editor (folder path only, not filter/sort). */
15
+ export declare const WIDGETIC_EDITOR_FILE_PICKER_INSTANCE_ID = "widgetic-editor-file-picker";
16
+ /** Toggles whether this instance may write its folder path to localStorage (set from FileBrowser props). */
17
+ export declare function setPersistFolderPath(instanceId: string, enabled: boolean): void;
18
+ export declare function shouldPersistFolderPath(instanceId: string): boolean;
14
19
  declare function createNavigationStore(instanceId?: string): {
15
20
  subscribe: (this: void, run: import("svelte/store").Subscriber<NavigationState>, invalidate?: () => void) => import("svelte/store").Unsubscriber;
16
21
  navigateToFolder: (newPath: string[], forceNavigation?: boolean) => void;
@@ -42,6 +42,27 @@ function arePathsEqual(path1, path2) {
42
42
  export function getStorageKey(instanceId = 'default') {
43
43
  return `file-browser-navigation-${instanceId}`;
44
44
  }
45
+ /** 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 = {};
48
+ /** Toggles whether this instance may write its folder path to localStorage (set from FileBrowser props). */
49
+ export function setPersistFolderPath(instanceId, enabled) {
50
+ persistFolderPathByInstance[instanceId] = enabled;
51
+ }
52
+ export function shouldPersistFolderPath(instanceId) {
53
+ return persistFolderPathByInstance[instanceId] === true;
54
+ }
55
+ function saveNavigationStateToStorage(instanceId, state) {
56
+ if (!browser || !shouldPersistFolderPath(instanceId)) {
57
+ return;
58
+ }
59
+ try {
60
+ localStorage.setItem(getStorageKey(instanceId), JSON.stringify(state));
61
+ }
62
+ catch (error) {
63
+ console.error('Error saving navigation state:', error);
64
+ }
65
+ }
45
66
  function createNavigationStore(instanceId = 'default') {
46
67
  const STORAGE_KEY = getStorageKey(instanceId);
47
68
  // Get the initial state from storage
@@ -98,12 +119,7 @@ function createNavigationStore(instanceId = 'default') {
98
119
  pathsArray: [[]],
99
120
  currentIndex: 0
100
121
  };
101
- try {
102
- localStorage.setItem(STORAGE_KEY, JSON.stringify(rootState));
103
- }
104
- catch (error) {
105
- console.error('Error saving navigation state:', error);
106
- }
122
+ saveNavigationStateToStorage(instanceId, rootState);
107
123
  return rootState;
108
124
  }
109
125
  return state;
@@ -183,14 +199,7 @@ function createNavigationStore(instanceId = 'default') {
183
199
  pathsArray: [[]],
184
200
  currentIndex: 0
185
201
  };
186
- if (browser) {
187
- try {
188
- localStorage.setItem(STORAGE_KEY, JSON.stringify(rootState));
189
- }
190
- catch (error) {
191
- console.error('Error saving navigation state:', error);
192
- }
193
- }
202
+ saveNavigationStateToStorage(instanceId, rootState);
194
203
  return rootState;
195
204
  }
196
205
  // Proceed with navigation
@@ -198,8 +207,6 @@ function createNavigationStore(instanceId = 'default') {
198
207
  // already exists at the end of the history
199
208
  const lastPathIndex = state.pathsArray.length - 1;
200
209
  const lastPath = lastPathIndex >= 0 ? state.pathsArray[lastPathIndex] : null;
201
- // Get the current persistHistory setting
202
- const isPersistHistoryEnabled = get(persistHistory);
203
210
  // SIMPLIFY: Always check if the path is already the last item in the history,
204
211
  // and if so, just skip adding a duplicate regardless of other conditions
205
212
  if (lastPath && arePathsEqual(lastPath, newPath)) {
@@ -216,14 +223,7 @@ function createNavigationStore(instanceId = 'default') {
216
223
  ...state,
217
224
  currentIndex: lastPathIndex
218
225
  };
219
- if (browser) {
220
- try {
221
- localStorage.setItem(STORAGE_KEY, JSON.stringify(newState));
222
- }
223
- catch (error) {
224
- console.error('Error saving navigation state:', error);
225
- }
226
- }
226
+ saveNavigationStateToStorage(instanceId, newState);
227
227
  return newState;
228
228
  }
229
229
  // Otherwise just return the current state unchanged
@@ -245,15 +245,7 @@ function createNavigationStore(instanceId = 'default') {
245
245
  ...state,
246
246
  currentIndex: existingPathIndex
247
247
  };
248
- if (browser) {
249
- try {
250
- localStorage.setItem(STORAGE_KEY, JSON.stringify(newState));
251
- }
252
- catch (error) {
253
- if (showLogs)
254
- console.error('Error saving navigation state:', error);
255
- }
256
- }
248
+ saveNavigationStateToStorage(instanceId, newState);
257
249
  return newState;
258
250
  }
259
251
  // If we get here, we're adding a new unique path to the history
@@ -269,16 +261,7 @@ function createNavigationStore(instanceId = 'default') {
269
261
  currentIndex: newState.currentIndex,
270
262
  newPath: newPath.join('/')
271
263
  });
272
- // Save to localStorage if persistHistory is enabled
273
- if (browser) {
274
- try {
275
- localStorage.setItem(STORAGE_KEY, JSON.stringify(newState));
276
- }
277
- catch (error) {
278
- if (showLogs)
279
- console.error('Error saving navigation state:', error);
280
- }
281
- }
264
+ saveNavigationStateToStorage(instanceId, newState);
282
265
  return newState;
283
266
  });
284
267
  },
@@ -289,9 +272,7 @@ function createNavigationStore(instanceId = 'default') {
289
272
  ...state,
290
273
  currentIndex: state.currentIndex - 1
291
274
  };
292
- if (browser) {
293
- localStorage.setItem(STORAGE_KEY, JSON.stringify(newState));
294
- }
275
+ saveNavigationStateToStorage(instanceId, newState);
295
276
  return newState;
296
277
  }
297
278
  return state;
@@ -304,9 +285,7 @@ function createNavigationStore(instanceId = 'default') {
304
285
  ...state,
305
286
  currentIndex: state.currentIndex + 1
306
287
  };
307
- if (browser) {
308
- localStorage.setItem(STORAGE_KEY, JSON.stringify(newState));
309
- }
288
+ saveNavigationStateToStorage(instanceId, newState);
310
289
  return newState;
311
290
  }
312
291
  return state;
@@ -318,8 +297,13 @@ function createNavigationStore(instanceId = 'default') {
318
297
  currentIndex: 0
319
298
  };
320
299
  set(initialState);
321
- if (browser) {
322
- localStorage.removeItem(STORAGE_KEY);
300
+ if (browser && shouldPersistFolderPath(instanceId)) {
301
+ try {
302
+ localStorage.removeItem(STORAGE_KEY);
303
+ }
304
+ catch (error) {
305
+ console.error('Error clearing navigation state:', error);
306
+ }
323
307
  }
324
308
  },
325
309
  cleanupPaths: (deletedFolderId) => {
@@ -403,11 +387,9 @@ function createNavigationStore(instanceId = 'default') {
403
387
  currentIndex: newCurrentIndex,
404
388
  currentPath: newPaths[newCurrentIndex]
405
389
  });
406
- // Save to localStorage
407
- if (browser) {
390
+ saveNavigationStateToStorage(instanceId, newState);
391
+ if (browser && shouldPersistFolderPath(instanceId)) {
408
392
  try {
409
- localStorage.setItem(STORAGE_KEY, JSON.stringify(newState));
410
- // Also clean up any other related localStorage items
411
393
  for (const key of Object.keys(localStorage)) {
412
394
  if (key.startsWith(`${STORAGE_KEY}-`)) {
413
395
  localStorage.removeItem(key);
@@ -415,7 +397,7 @@ function createNavigationStore(instanceId = 'default') {
415
397
  }
416
398
  }
417
399
  catch (error) {
418
- console.error('Error saving navigation state:', error);
400
+ console.error('Error cleaning navigation-related localStorage keys:', error);
419
401
  }
420
402
  }
421
403
  return newState;
@@ -482,15 +464,7 @@ function createNavigationStore(instanceId = 'default') {
482
464
  currentIndex: newState.currentIndex,
483
465
  currentPath: newState.pathsArray[newState.currentIndex]
484
466
  });
485
- // Save to localStorage
486
- if (browser) {
487
- try {
488
- localStorage.setItem(STORAGE_KEY, JSON.stringify(newState));
489
- }
490
- catch (error) {
491
- console.error('Error saving navigation state:', error);
492
- }
493
- }
467
+ saveNavigationStateToStorage(instanceId, newState);
494
468
  return newState;
495
469
  });
496
470
  }
@@ -606,8 +580,7 @@ export function getStoredState(instanceId) {
606
580
  return state;
607
581
  }
608
582
  catch (error) {
609
- if (showLogs)
610
- console.error('Error reading navigation state:', error);
583
+ console.warn('Could not read navigation state from localStorage, using root:', error);
611
584
  return null;
612
585
  }
613
586
  }