@widgetic/file-browser 0.5.40 → 0.5.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/core/FileBrowser.svelte +108 -55
- package/dist/components/core/FileBrowser.svelte.d.ts +5 -1
- package/dist/components/core/FileUploader.svelte +49 -15
- package/dist/components/core/RecentFiles.svelte +23 -11
- package/dist/components/core/RecentFiles.svelte.d.ts +1 -0
- package/dist/components/core/SearchDropdown.svelte +124 -26
- package/dist/components/core/UploadPanel.svelte +1 -1
- package/dist/components/items/FileItem.svelte +12 -2
- package/dist/components/items/FolderItem.svelte +8 -1
- package/dist/components/modals/index.d.ts +0 -1
- package/dist/components/modals/index.js +0 -1
- package/dist/components/previews/FilePreview.svelte +198 -31
- package/dist/components/previews/FilePreview.svelte.d.ts +1 -0
- package/dist/components/previews/ImagePreview.svelte +60 -31
- package/dist/components/previews/ImagePreview.svelte.d.ts +3 -0
- package/dist/components/previews/PreviewHeaderBar.svelte +33 -25
- package/dist/components/previews/PreviewHeaderBar.svelte.d.ts +2 -0
- package/dist/components/ui/DragSelect.svelte +85 -67
- package/dist/components/ui/DragSelect.svelte.d.ts +1 -0
- package/dist/data/demoContent.json +13 -11
- package/dist/i18n/messages.d.ts +0 -1
- package/dist/i18n/messages.js +0 -1
- package/dist/stores/navigationStore.d.ts +5 -0
- package/dist/stores/navigationStore.js +40 -67
- package/dist/utils/escapeSelectionAction.d.ts +18 -0
- package/dist/utils/escapeSelectionAction.js +18 -0
- package/dist/utils/imagePreviewCache.d.ts +16 -0
- package/dist/utils/imagePreviewCache.js +78 -0
- package/dist/utils/imagePreviewVisualState.d.ts +19 -0
- package/dist/utils/imagePreviewVisualState.js +22 -0
- package/dist/utils/menuKeydownBubble.d.ts +9 -0
- package/dist/utils/menuKeydownBubble.js +11 -0
- package/dist/utils/previewNavigation.d.ts +4 -0
- package/dist/utils/previewNavigation.js +17 -0
- package/dist/utils/recentFiles.d.ts +6 -0
- package/dist/utils/recentFiles.js +21 -0
- package/dist/utils/recentFilesLimit.d.ts +8 -0
- package/dist/utils/recentFilesLimit.js +17 -0
- package/dist/utils/searchEscapeAction.d.ts +10 -0
- package/dist/utils/searchEscapeAction.js +12 -0
- package/dist/utils/searchItems.d.ts +2 -4
- package/dist/utils/searchItems.js +12 -5
- package/dist/utils/searchNavigation.d.ts +12 -0
- package/dist/utils/searchNavigation.js +42 -0
- package/dist/utils/uploadDisplayProgress.d.ts +4 -0
- package/dist/utils/uploadDisplayProgress.js +9 -0
- package/dist/utils/uploadPanelProgress.d.ts +5 -0
- package/dist/utils/uploadPanelProgress.js +17 -0
- package/package.json +1 -1
- package/dist/components/modals/SearchModal.svelte +0 -296
- package/dist/components/modals/SearchModal.svelte.d.ts +0 -27
|
@@ -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(
|
|
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
|
|
215
|
-
|
|
216
|
-
startX = e.clientX -
|
|
217
|
-
startY = e.clientY -
|
|
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
|
|
234
|
-
|
|
235
|
-
currentX = e.clientX -
|
|
236
|
-
currentY = e.clientY -
|
|
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(
|
|
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 =
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
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
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
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 (!
|
|
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
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
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
|
-
|
|
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
|
-
|
|
572
|
+
const scrollableElement = getScrollableElement();
|
|
573
|
+
if (!isDragging || !scrollContainer || !scrollableElement || !container) return;
|
|
554
574
|
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
const
|
|
559
|
-
const
|
|
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
|
-
|
|
565
|
-
|
|
585
|
+
const previousScrollTop = scrollableElement.scrollTop;
|
|
586
|
+
scrollableElement.scrollTop -= SCROLL_SPEED;
|
|
587
|
+
scrolled = scrollableElement.scrollTop !== previousScrollTop;
|
|
566
588
|
} else if (distanceFromBottom < SCROLL_THRESHOLD) {
|
|
567
|
-
|
|
568
|
-
|
|
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": "
|
|
480
|
+
"name": "image 30.jpg",
|
|
481
481
|
"type": "file",
|
|
482
|
-
"size":
|
|
482
|
+
"size": 2400000,
|
|
483
|
+
"width": 1024,
|
|
484
|
+
"height": 683,
|
|
483
485
|
"modified": "2023-09-24T16:30:00Z",
|
|
484
|
-
"url": "
|
|
485
|
-
"thumbnail": "
|
|
486
|
-
"hash": "
|
|
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
|
|
1161
|
+
"name": "image 29.jpg",
|
|
1160
1162
|
"type": "file",
|
|
1161
|
-
"size":
|
|
1163
|
+
"size": 3050000,
|
|
1162
1164
|
"width": 1024,
|
|
1163
1165
|
"height": 683,
|
|
1164
|
-
"modified": "2024-09-27T11:
|
|
1165
|
-
"url": "image/image
|
|
1166
|
-
"thumbnail": "thumbnail/image
|
|
1167
|
-
"hash": "
|
|
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
|
}
|
package/dist/i18n/messages.d.ts
CHANGED
|
@@ -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";
|
package/dist/i18n/messages.js
CHANGED
|
@@ -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',
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type EscapeSelectionAction = 'clear-selection' | 'none';
|
|
2
|
+
export interface EscapeSelectionContext {
|
|
3
|
+
key: string;
|
|
4
|
+
defaultPrevented: boolean;
|
|
5
|
+
previewOpen: boolean;
|
|
6
|
+
designSystemModalOpen: boolean;
|
|
7
|
+
inputFocused: boolean;
|
|
8
|
+
rubberBandDragActive: boolean;
|
|
9
|
+
innerEscapeHandlerOpen: boolean;
|
|
10
|
+
selectionCount: number;
|
|
11
|
+
clearableSelectionCount: number;
|
|
12
|
+
/** Editor single-file picker: Escape is handled by the host overlay, never clear here. */
|
|
13
|
+
singleFilePicker?: boolean;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Whether Escape should clear the file-browser selection (preview and inner UI keep Escape first).
|
|
17
|
+
*/
|
|
18
|
+
export declare function escapeSelectionAction(ctx: EscapeSelectionContext): EscapeSelectionAction;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether Escape should clear the file-browser selection (preview and inner UI keep Escape first).
|
|
3
|
+
*/
|
|
4
|
+
export function escapeSelectionAction(ctx) {
|
|
5
|
+
if (ctx.key !== 'Escape')
|
|
6
|
+
return 'none';
|
|
7
|
+
if (ctx.defaultPrevented)
|
|
8
|
+
return 'none';
|
|
9
|
+
if (ctx.previewOpen || ctx.designSystemModalOpen)
|
|
10
|
+
return 'none';
|
|
11
|
+
if (ctx.inputFocused || ctx.rubberBandDragActive || ctx.innerEscapeHandlerOpen)
|
|
12
|
+
return 'none';
|
|
13
|
+
if (ctx.singleFilePicker)
|
|
14
|
+
return 'none';
|
|
15
|
+
if (ctx.clearableSelectionCount <= 0)
|
|
16
|
+
return 'none';
|
|
17
|
+
return 'clear-selection';
|
|
18
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare function rememberImageNaturalSize(url: string, width: number, height: number): void;
|
|
2
|
+
export declare function getCachedImageNaturalSize(url: string): {
|
|
3
|
+
width: number;
|
|
4
|
+
height: number;
|
|
5
|
+
} | undefined;
|
|
6
|
+
/**
|
|
7
|
+
* The natural size of a picture the browser already holds decoded (shown before, in a tile or in this preview), found at once.
|
|
8
|
+
* A picture that is not in the browser's memory is not waited for: it starts loading and this returns nothing.
|
|
9
|
+
*/
|
|
10
|
+
export declare function probeDecodedImage(url: string): {
|
|
11
|
+
width: number;
|
|
12
|
+
height: number;
|
|
13
|
+
} | undefined;
|
|
14
|
+
/** Warm the decoder cache; resolves when decode finishes or the request fails. */
|
|
15
|
+
export declare function preloadImageUrl(url: string): Promise<void>;
|
|
16
|
+
export declare function clearImagePreviewCacheForTests(): void;
|