@widgetic/file-browser 0.5.17
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/README.md +131 -0
- package/dist/components/FolderTree.svelte +143 -0
- package/dist/components/FolderTree.svelte.d.ts +32 -0
- package/dist/components/core/FileBrowser.css +79 -0
- package/dist/components/core/FileBrowser.svelte +3989 -0
- package/dist/components/core/FileBrowser.svelte.d.ts +55 -0
- package/dist/components/core/FileUploader.svelte +1152 -0
- package/dist/components/core/FileUploader.svelte.d.ts +43 -0
- package/dist/components/core/Header.svelte +143 -0
- package/dist/components/core/Header.svelte.d.ts +36 -0
- package/dist/components/core/RecentFiles.svelte +753 -0
- package/dist/components/core/RecentFiles.svelte.d.ts +37 -0
- package/dist/components/core/UploadStatus.svelte +133 -0
- package/dist/components/core/UploadStatus.svelte.d.ts +28 -0
- package/dist/components/core/UploadStatusList.svelte +138 -0
- package/dist/components/core/UploadStatusList.svelte.d.ts +33 -0
- package/dist/components/core/index.d.ts +4 -0
- package/dist/components/core/index.js +4 -0
- package/dist/components/index.d.ts +6 -0
- package/dist/components/index.js +8 -0
- package/dist/components/items/FileItem.svelte +684 -0
- package/dist/components/items/FileItem.svelte.d.ts +34 -0
- package/dist/components/items/FolderItem.svelte +77 -0
- package/dist/components/items/FolderItem.svelte.d.ts +27 -0
- package/dist/components/items/index.d.ts +2 -0
- package/dist/components/items/index.js +2 -0
- package/dist/components/modals/MoveDialog.svelte +539 -0
- package/dist/components/modals/MoveDialog.svelte.d.ts +32 -0
- package/dist/components/modals/NewFolderButton.svelte +25 -0
- package/dist/components/modals/NewFolderButton.svelte.d.ts +20 -0
- package/dist/components/modals/README.md +99 -0
- package/dist/components/modals/SearchModal.svelte +500 -0
- package/dist/components/modals/SearchModal.svelte.d.ts +28 -0
- package/dist/components/modals/SelectedFilesModal.svelte +291 -0
- package/dist/components/modals/SelectedFilesModal.svelte.d.ts +32 -0
- package/dist/components/modals/index.d.ts +6 -0
- package/dist/components/modals/index.js +9 -0
- package/dist/components/previews/AudioPlayer.svelte +117 -0
- package/dist/components/previews/AudioPlayer.svelte.d.ts +22 -0
- package/dist/components/previews/ErrorPreview.svelte +12 -0
- package/dist/components/previews/ErrorPreview.svelte.d.ts +20 -0
- package/dist/components/previews/FilePreview.svelte +475 -0
- package/dist/components/previews/FilePreview.svelte.d.ts +31 -0
- package/dist/components/previews/FontPreview.svelte +82 -0
- package/dist/components/previews/FontPreview.svelte.d.ts +22 -0
- package/dist/components/previews/ImagePreview.svelte +551 -0
- package/dist/components/previews/ImagePreview.svelte.d.ts +27 -0
- package/dist/components/previews/TextPreview.svelte +92 -0
- package/dist/components/previews/TextPreview.svelte.d.ts +20 -0
- package/dist/components/previews/VideoPlayer.svelte +268 -0
- package/dist/components/previews/VideoPlayer.svelte.d.ts +22 -0
- package/dist/components/previews/WaveformVisualizer.svelte +240 -0
- package/dist/components/previews/WaveformVisualizer.svelte.d.ts +20 -0
- package/dist/components/previews/index.d.ts +8 -0
- package/dist/components/previews/index.js +8 -0
- package/dist/components/ui/ControlToolbar.svelte +342 -0
- package/dist/components/ui/ControlToolbar.svelte.d.ts +36 -0
- package/dist/components/ui/DragSelect.svelte +815 -0
- package/dist/components/ui/DragSelect.svelte.d.ts +31 -0
- package/dist/components/ui/DropdownMenu.svelte +83 -0
- package/dist/components/ui/DropdownMenu.svelte.d.ts +25 -0
- package/dist/components/ui/FileIcon.svelte +65 -0
- package/dist/components/ui/FileIcon.svelte.d.ts +25 -0
- package/dist/components/ui/FileMetadata.svelte +26 -0
- package/dist/components/ui/FileMetadata.svelte.d.ts +21 -0
- package/dist/components/ui/LoadingSkeleton.svelte +26 -0
- package/dist/components/ui/LoadingSkeleton.svelte.d.ts +22 -0
- package/dist/components/ui/SearchResults.svelte +37 -0
- package/dist/components/ui/SearchResults.svelte.d.ts +21 -0
- package/dist/components/ui/VirtualList.svelte +106 -0
- package/dist/components/ui/VirtualList.svelte.d.ts +45 -0
- package/dist/components/ui/index.d.ts +8 -0
- package/dist/components/ui/index.js +8 -0
- package/dist/config.d.ts +7 -0
- package/dist/config.js +14 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +11 -0
- package/dist/static/favicon.png +0 -0
- package/dist/static/files/audio/audio-file.mp3 +0 -0
- package/dist/static/files/document/-missing-file.txt +1 -0
- package/dist/static/files/document/HeliosDesign Website Project Brief Sample.pdf +0 -0
- package/dist/static/files/document/RFP-NEC_Website-Development_2021-August.pdf +0 -0
- package/dist/static/files/document/The World Before Calculus.pdf +0 -0
- package/dist/static/files/document/specs.txt +15 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-Bold.otf +0 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-BoldItalic.otf +0 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-Book.otf +0 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-BookItalic.otf +0 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-Heavy.otf +0 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-HeavyItalic.otf +0 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-Light.otf +0 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-LightItalic.otf +0 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-Medium.otf +0 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-MediumItalic.otf +0 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-Semibold.otf +0 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-SemiboldItalic.otf +0 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-Thin.otf +0 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-ThinItalic.otf +0 -0
- package/dist/static/files/font/Kimpo/Kimpo-Bold.otf +0 -0
- package/dist/static/files/font/Kimpo/Kimpo-Regular.otf +0 -0
- package/dist/static/files/image/image 1.jpg +0 -0
- package/dist/static/files/image/image 10.jpg +0 -0
- package/dist/static/files/image/image 11.jpg +0 -0
- package/dist/static/files/image/image 12.jpg +0 -0
- package/dist/static/files/image/image 13.jpg +0 -0
- package/dist/static/files/image/image 14.jpg +0 -0
- package/dist/static/files/image/image 15.jpg +0 -0
- package/dist/static/files/image/image 16.jpg +0 -0
- package/dist/static/files/image/image 17.jpg +0 -0
- package/dist/static/files/image/image 18.jpg +0 -0
- package/dist/static/files/image/image 19.jpg +0 -0
- package/dist/static/files/image/image 2.jpg +0 -0
- package/dist/static/files/image/image 20.jpg +0 -0
- package/dist/static/files/image/image 21.jpg +0 -0
- package/dist/static/files/image/image 22.jpg +0 -0
- package/dist/static/files/image/image 23.jpg +0 -0
- package/dist/static/files/image/image 24.jpg +0 -0
- package/dist/static/files/image/image 25.jpg +0 -0
- package/dist/static/files/image/image 26.jpg +0 -0
- package/dist/static/files/image/image 27.jpg +0 -0
- package/dist/static/files/image/image 28.jpg +0 -0
- package/dist/static/files/image/image 29.jpg +0 -0
- package/dist/static/files/image/image 3.jpg +0 -0
- package/dist/static/files/image/image 30.jpg +0 -0
- package/dist/static/files/image/image 31.jpg +0 -0
- package/dist/static/files/image/image 32.jpg +0 -0
- package/dist/static/files/image/image 33.jpg +0 -0
- package/dist/static/files/image/image 34.jpg +0 -0
- package/dist/static/files/image/image 35.jpg +0 -0
- package/dist/static/files/image/image 36.jpg +0 -0
- package/dist/static/files/image/image 37.jpg +0 -0
- package/dist/static/files/image/image 38.jpg +0 -0
- package/dist/static/files/image/image 39.jpg +0 -0
- package/dist/static/files/image/image 4.jpg +0 -0
- package/dist/static/files/image/image 40.jpg +0 -0
- package/dist/static/files/image/image 41.jpg +0 -0
- package/dist/static/files/image/image 42.jpg +0 -0
- package/dist/static/files/image/image 43.jpg +0 -0
- package/dist/static/files/image/image 44.jpg +0 -0
- package/dist/static/files/image/image 45.jpg +0 -0
- package/dist/static/files/image/image 46.jpg +0 -0
- package/dist/static/files/image/image 47.jpg +0 -0
- package/dist/static/files/image/image 48.jpg +0 -0
- package/dist/static/files/image/image 49.jpg +0 -0
- package/dist/static/files/image/image 5.jpg +0 -0
- package/dist/static/files/image/image 50.jpg +0 -0
- package/dist/static/files/image/image 51.jpg +0 -0
- package/dist/static/files/image/image 52.jpg +0 -0
- package/dist/static/files/image/image 53.jpg +0 -0
- package/dist/static/files/image/image 54.jpg +0 -0
- package/dist/static/files/image/image 55.jpg +0 -0
- package/dist/static/files/image/image 56.jpg +0 -0
- package/dist/static/files/image/image 57.jpg +0 -0
- package/dist/static/files/image/image 58.jpg +0 -0
- package/dist/static/files/image/image 59.jpg +0 -0
- package/dist/static/files/image/image 6.jpg +0 -0
- package/dist/static/files/image/image 60.jpg +0 -0
- package/dist/static/files/image/image 61.jpg +0 -0
- package/dist/static/files/image/image 62.jpg +0 -0
- package/dist/static/files/image/image 63.jpg +0 -0
- package/dist/static/files/image/image 64.jpg +0 -0
- package/dist/static/files/image/image 65.jpg +0 -0
- package/dist/static/files/image/image 66.jpg +0 -0
- package/dist/static/files/image/image 67.jpg +0 -0
- package/dist/static/files/image/image 68.jpg +0 -0
- package/dist/static/files/image/image 7.jpg +0 -0
- package/dist/static/files/image/image 8.jpg +0 -0
- package/dist/static/files/image/image 9.jpg +0 -0
- package/dist/static/files/svg/astronaut.svg +30 -0
- package/dist/static/files/svg/cook.svg +30 -0
- package/dist/static/files/svg/dj.svg +28 -0
- package/dist/static/files/svg/doctor.svg +29 -0
- package/dist/static/files/svg/farmer.svg +43 -0
- package/dist/static/files/svg/fire fighter.svg +40 -0
- package/dist/static/files/svg/plumber.svg +32 -0
- package/dist/static/files/svg/santa.svg +34 -0
- package/dist/static/files/svg/scientist.svg +31 -0
- package/dist/static/files/svg/student.svg +32 -0
- package/dist/static/files/thumbnail/image 1.jpg +0 -0
- package/dist/static/files/thumbnail/image 10.jpg +0 -0
- package/dist/static/files/thumbnail/image 11.jpg +0 -0
- package/dist/static/files/thumbnail/image 12.jpg +0 -0
- package/dist/static/files/thumbnail/image 13.jpg +0 -0
- package/dist/static/files/thumbnail/image 14.jpg +0 -0
- package/dist/static/files/thumbnail/image 15.jpg +0 -0
- package/dist/static/files/thumbnail/image 16.jpg +0 -0
- package/dist/static/files/thumbnail/image 17.jpg +0 -0
- package/dist/static/files/thumbnail/image 18.jpg +0 -0
- package/dist/static/files/thumbnail/image 19.jpg +0 -0
- package/dist/static/files/thumbnail/image 2.jpg +0 -0
- package/dist/static/files/thumbnail/image 20.jpg +0 -0
- package/dist/static/files/thumbnail/image 21.jpg +0 -0
- package/dist/static/files/thumbnail/image 22.jpg +0 -0
- package/dist/static/files/thumbnail/image 23.jpg +0 -0
- package/dist/static/files/thumbnail/image 24.jpg +0 -0
- package/dist/static/files/thumbnail/image 25.jpg +0 -0
- package/dist/static/files/thumbnail/image 26.jpg +0 -0
- package/dist/static/files/thumbnail/image 27.jpg +0 -0
- package/dist/static/files/thumbnail/image 28.jpg +0 -0
- package/dist/static/files/thumbnail/image 29.jpg +0 -0
- package/dist/static/files/thumbnail/image 3.jpg +0 -0
- package/dist/static/files/thumbnail/image 30.jpg +0 -0
- package/dist/static/files/thumbnail/image 31.jpg +0 -0
- package/dist/static/files/thumbnail/image 32.jpg +0 -0
- package/dist/static/files/thumbnail/image 33.jpg +0 -0
- package/dist/static/files/thumbnail/image 34.jpg +0 -0
- package/dist/static/files/thumbnail/image 35.jpg +0 -0
- package/dist/static/files/thumbnail/image 36.jpg +0 -0
- package/dist/static/files/thumbnail/image 37.jpg +0 -0
- package/dist/static/files/thumbnail/image 38.jpg +0 -0
- package/dist/static/files/thumbnail/image 39.jpg +0 -0
- package/dist/static/files/thumbnail/image 4.jpg +0 -0
- package/dist/static/files/thumbnail/image 40.jpg +0 -0
- package/dist/static/files/thumbnail/image 41.jpg +0 -0
- package/dist/static/files/thumbnail/image 42.jpg +0 -0
- package/dist/static/files/thumbnail/image 43.jpg +0 -0
- package/dist/static/files/thumbnail/image 44.jpg +0 -0
- package/dist/static/files/thumbnail/image 45.jpg +0 -0
- package/dist/static/files/thumbnail/image 46.jpg +0 -0
- package/dist/static/files/thumbnail/image 47.jpg +0 -0
- package/dist/static/files/thumbnail/image 48.jpg +0 -0
- package/dist/static/files/thumbnail/image 49.jpg +0 -0
- package/dist/static/files/thumbnail/image 5.jpg +0 -0
- package/dist/static/files/thumbnail/image 50.jpg +0 -0
- package/dist/static/files/thumbnail/image 51.jpg +0 -0
- package/dist/static/files/thumbnail/image 52.jpg +0 -0
- package/dist/static/files/thumbnail/image 53.jpg +0 -0
- package/dist/static/files/thumbnail/image 54.jpg +0 -0
- package/dist/static/files/thumbnail/image 55.jpg +0 -0
- package/dist/static/files/thumbnail/image 56.jpg +0 -0
- package/dist/static/files/thumbnail/image 57.jpg +0 -0
- package/dist/static/files/thumbnail/image 58.jpg +0 -0
- package/dist/static/files/thumbnail/image 59.jpg +0 -0
- package/dist/static/files/thumbnail/image 6.jpg +0 -0
- package/dist/static/files/thumbnail/image 60.jpg +0 -0
- package/dist/static/files/thumbnail/image 61.jpg +0 -0
- package/dist/static/files/thumbnail/image 62.jpg +0 -0
- package/dist/static/files/thumbnail/image 63.jpg +0 -0
- package/dist/static/files/thumbnail/image 64.jpg +0 -0
- package/dist/static/files/thumbnail/image 65.jpg +0 -0
- package/dist/static/files/thumbnail/image 66.jpg +0 -0
- package/dist/static/files/thumbnail/image 67.jpg +0 -0
- package/dist/static/files/thumbnail/image 68.jpg +0 -0
- package/dist/static/files/thumbnail/image 7.jpg +0 -0
- package/dist/static/files/thumbnail/image 8.jpg +0 -0
- package/dist/static/files/thumbnail/image 9.jpg +0 -0
- package/dist/static/files/video/video-file.mp4 +0 -0
- package/dist/static/files/video/video-file.png +0 -0
- package/dist/static/icons/audio.svg +7 -0
- package/dist/static/icons/check.svg +3 -0
- package/dist/static/icons/checked.svg +4 -0
- package/dist/static/icons/close.svg +11 -0
- package/dist/static/icons/document.svg +11 -0
- package/dist/static/icons/dots.svg +1 -0
- package/dist/static/icons/download.svg +1 -0
- package/dist/static/icons/empty-folder.svg +24 -0
- package/dist/static/icons/error.svg +5 -0
- package/dist/static/icons/file-upload.svg +1 -0
- package/dist/static/icons/folder-plus.svg +1 -0
- package/dist/static/icons/folder.svg +28 -0
- package/dist/static/icons/jump-to-folder.svg +1 -0
- package/dist/static/icons/move.svg +1 -0
- package/dist/static/icons/new-folder.svg +5 -0
- package/dist/static/icons/pdf.svg +6 -0
- package/dist/static/icons/player-pause.svg +1 -0
- package/dist/static/icons/player-play.svg +3 -0
- package/dist/static/icons/plus.svg +1 -0
- package/dist/static/icons/rename.svg +1 -0
- package/dist/static/icons/search.svg +1 -0
- package/dist/static/icons/trash.svg +1 -0
- package/dist/static/icons/unorganized-folder.svg +60 -0
- package/dist/stores/dragStore.d.ts +2 -0
- package/dist/stores/dragStore.js +2 -0
- package/dist/stores/fileStore.d.ts +36 -0
- package/dist/stores/fileStore.js +166 -0
- package/dist/stores/folderCountStore.d.ts +5 -0
- package/dist/stores/folderCountStore.js +49 -0
- package/dist/stores/index.d.ts +7 -0
- package/dist/stores/index.js +8 -0
- package/dist/stores/missingFilesStore.d.ts +3 -0
- package/dist/stores/missingFilesStore.js +14 -0
- package/dist/stores/navigationStore.d.ts +36 -0
- package/dist/stores/navigationStore.js +615 -0
- package/dist/stores/persistentSelectStore.d.ts +17 -0
- package/dist/stores/persistentSelectStore.js +170 -0
- package/dist/stores/searchStore.d.ts +1 -0
- package/dist/stores/searchStore.js +2 -0
- package/dist/stores/uploadApiStore.d.ts +13 -0
- package/dist/stores/uploadApiStore.js +36 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +3 -0
- package/dist/types/pdf.d.ts +3 -0
- package/dist/types.d.ts +23 -0
- package/dist/types.js +1 -0
- package/dist/utils/apiConfig.d.ts +9 -0
- package/dist/utils/apiConfig.js +19 -0
- package/dist/utils/dateUtils.d.ts +2 -0
- package/dist/utils/dateUtils.js +38 -0
- package/dist/utils/fileOperations.d.ts +36 -0
- package/dist/utils/fileOperations.js +573 -0
- package/dist/utils/fileTypes.d.ts +17 -0
- package/dist/utils/fileTypes.js +110 -0
- package/dist/utils/fileUtils.d.ts +15 -0
- package/dist/utils/fileUtils.js +112 -0
- package/dist/utils/folderUtils.d.ts +4 -0
- package/dist/utils/folderUtils.js +26 -0
- package/dist/utils/imageTransform.d.ts +22 -0
- package/dist/utils/imageTransform.js +60 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.js +6 -0
- package/dist/utils/resolveFileUrl.d.ts +6 -0
- package/dist/utils/resolveFileUrl.js +21 -0
- package/dist/utils/userUploadsStorage.d.ts +27 -0
- package/dist/utils/userUploadsStorage.js +168 -0
- package/dist/utils/widgeticTusUpload.d.ts +18 -0
- package/dist/utils/widgeticTusUpload.js +131 -0
- package/dist/utils/widgeticUpload.d.ts +29 -0
- package/dist/utils/widgeticUpload.js +105 -0
- package/package.json +156 -0
|
@@ -0,0 +1,815 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { onMount, createEventDispatcher, tick } from 'svelte';
|
|
3
|
+
const dispatch = createEventDispatcher<{
|
|
4
|
+
select: { added: FileSystemItem[]; removed: FileSystemItem[] };
|
|
5
|
+
}>();
|
|
6
|
+
|
|
7
|
+
import type { FileSystemItem } from '../../types';
|
|
8
|
+
import { isModalOpen } from '@widgetic/design-system/components/modals/modalStore';
|
|
9
|
+
// Import the persistent selection store
|
|
10
|
+
import { persistentSelectStore } from '../../stores/persistentSelectStore';
|
|
11
|
+
import type { FileFilterType } from '../../utils/fileTypes';
|
|
12
|
+
|
|
13
|
+
export let container: HTMLElement;
|
|
14
|
+
export let enabled: boolean = true;
|
|
15
|
+
export let items: FileSystemItem[] = [];
|
|
16
|
+
export let scrollContainer: HTMLElement | null = null;
|
|
17
|
+
// export let scrollBarSize: number = 0;
|
|
18
|
+
|
|
19
|
+
// Add current filter as a prop
|
|
20
|
+
export let currentFilter: FileFilterType = 'all';
|
|
21
|
+
|
|
22
|
+
let selectionBox: HTMLDivElement;
|
|
23
|
+
let isDragging = false;
|
|
24
|
+
let startX = 0;
|
|
25
|
+
let startY = 0;
|
|
26
|
+
let currentX = 0;
|
|
27
|
+
let currentY = 0;
|
|
28
|
+
let scrollStartY = 0;
|
|
29
|
+
let autoScrollInterval: number | null = null;
|
|
30
|
+
let selectedItemIds = new Set<string>();
|
|
31
|
+
let cleanup: (() => void) | null = null;
|
|
32
|
+
let initiallySelectedItems = new Set<string>();
|
|
33
|
+
let dragStartTime = 0;
|
|
34
|
+
let hasMovedEnough = false;
|
|
35
|
+
let mouseIsDown = false;
|
|
36
|
+
let startItemId: string | null = null;
|
|
37
|
+
let selectionBoxInitialized = false;
|
|
38
|
+
//
|
|
39
|
+
let showLogs = false;
|
|
40
|
+
|
|
41
|
+
// Drag threshold in pixels and time
|
|
42
|
+
const DRAG_DISTANCE_THRESHOLD = 5;
|
|
43
|
+
const DRAG_TIME_THRESHOLD = 50;
|
|
44
|
+
|
|
45
|
+
// Auto-scroll speed in pixels per frame
|
|
46
|
+
const SCROLL_SPEED = 10;
|
|
47
|
+
// Threshold in pixels from the top/bottom of the container to trigger auto-scroll
|
|
48
|
+
const SCROLL_THRESHOLD = 50;
|
|
49
|
+
|
|
50
|
+
// Track modal state
|
|
51
|
+
$: modalOpen = $isModalOpen;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Resets the selection box by hiding it
|
|
55
|
+
*/
|
|
56
|
+
function resetSelectionBox() {
|
|
57
|
+
if (selectionBox) {
|
|
58
|
+
selectionBox.style.display = 'none';
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Checks if an element is an input field or within a modal
|
|
64
|
+
* @param element Element to check
|
|
65
|
+
* @returns boolean indicating if the element is an input field or within a modal
|
|
66
|
+
*/
|
|
67
|
+
function isInputOrModal(element: HTMLElement | null): boolean {
|
|
68
|
+
if (!element) return false;
|
|
69
|
+
|
|
70
|
+
// Check if element is an input field
|
|
71
|
+
if (
|
|
72
|
+
element instanceof HTMLInputElement ||
|
|
73
|
+
element instanceof HTMLTextAreaElement ||
|
|
74
|
+
element instanceof HTMLSelectElement ||
|
|
75
|
+
element.isContentEditable ||
|
|
76
|
+
element.tagName === 'INPUT' ||
|
|
77
|
+
element.tagName === 'TEXTAREA' ||
|
|
78
|
+
element.tagName === 'SELECT'
|
|
79
|
+
) {
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Check if element is within a modal
|
|
84
|
+
if (
|
|
85
|
+
element.closest('.modal-content-inner-container') ||
|
|
86
|
+
element.closest('.base-modal-portal') ||
|
|
87
|
+
element.closest('.modal-content-root-container') ||
|
|
88
|
+
element.closest('.modal-backdrop-container')
|
|
89
|
+
) {
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Handle escape key to cancel selection
|
|
97
|
+
function handleKeyDown(e: KeyboardEvent) {
|
|
98
|
+
if (e.key === 'Escape' && isDragging) {
|
|
99
|
+
// Cancel the selection
|
|
100
|
+
mouseIsDown = false;
|
|
101
|
+
isDragging = false;
|
|
102
|
+
|
|
103
|
+
if (selectionBox) {
|
|
104
|
+
selectionBox.style.display = 'none';
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
stopAutoScroll();
|
|
108
|
+
|
|
109
|
+
// Remove hover effect from all items
|
|
110
|
+
container.querySelectorAll('.hover-effect').forEach(element => {
|
|
111
|
+
element.classList.remove('hover-effect');
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
// Reset flags
|
|
115
|
+
hasMovedEnough = false;
|
|
116
|
+
startItemId = null;
|
|
117
|
+
selectedItemIds.clear();
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Initialize the selection box
|
|
122
|
+
async function initSelectionBox() {
|
|
123
|
+
// Wait for DOM to be ready
|
|
124
|
+
await tick();
|
|
125
|
+
|
|
126
|
+
if (container && selectionBox && !selectionBoxInitialized) {
|
|
127
|
+
// Only append the selection box if it hasn't been initialized yet
|
|
128
|
+
container.appendChild(selectionBox);
|
|
129
|
+
selectionBoxInitialized = true;
|
|
130
|
+
if(showLogs) console.log('Selection box moved to container', container);
|
|
131
|
+
} else if (!container || !selectionBox) {
|
|
132
|
+
if(showLogs) console.log('Container or selection box not found');
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function initializeEventListeners() {
|
|
137
|
+
if (!container) {
|
|
138
|
+
if(showLogs) console.log('Container not available, skipping event listener initialization');
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Initialize the selection box only once
|
|
143
|
+
initSelectionBox();
|
|
144
|
+
|
|
145
|
+
const handleMouseDown = (e: MouseEvent) => {
|
|
146
|
+
// Immediately return if a modal is open
|
|
147
|
+
if (modalOpen) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Get the target element
|
|
152
|
+
const target = e.target as HTMLElement;
|
|
153
|
+
|
|
154
|
+
if (!enabled || e.button !== 0) return;
|
|
155
|
+
|
|
156
|
+
// Check if click is within the FileUploader
|
|
157
|
+
const fileUploader = target.closest('.file-uploader');
|
|
158
|
+
if (fileUploader) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Check if the target is an input field or within a modal
|
|
163
|
+
if (isInputOrModal(target)) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Don't start drag if clicking on interactive elements except for preview buttons
|
|
168
|
+
const button = target.closest('button');
|
|
169
|
+
const isPreviewButton = button?.getAttribute('aria-label')?.includes('Preview') ||
|
|
170
|
+
button?.getAttribute('aria-label')?.includes('Open folder');
|
|
171
|
+
const isInteractive = (target.closest('button') && !isPreviewButton) ||
|
|
172
|
+
target.closest('input') ||
|
|
173
|
+
target.closest('a') ||
|
|
174
|
+
target.closest('select');
|
|
175
|
+
if (isInteractive) return;
|
|
176
|
+
|
|
177
|
+
// Check if the click is within the scroll container
|
|
178
|
+
if (scrollContainer) {
|
|
179
|
+
const scrollRect = scrollContainer.getBoundingClientRect();
|
|
180
|
+
if (
|
|
181
|
+
e.clientX < scrollRect.left ||
|
|
182
|
+
e.clientX > scrollRect.right ||
|
|
183
|
+
e.clientY < scrollRect.top ||
|
|
184
|
+
e.clientY > scrollRect.bottom
|
|
185
|
+
) {
|
|
186
|
+
if(showLogs) console.log('Click outside scroll container, ignoring');
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Store the starting item ID
|
|
192
|
+
const itemContainer = target.closest('.item-container');
|
|
193
|
+
startItemId = itemContainer?.getAttribute('data-item-id') || null;
|
|
194
|
+
|
|
195
|
+
mouseIsDown = true;
|
|
196
|
+
dragStartTime = Date.now();
|
|
197
|
+
hasMovedEnough = false;
|
|
198
|
+
|
|
199
|
+
// Prevent default text selection and other browser behaviors
|
|
200
|
+
e.preventDefault();
|
|
201
|
+
e.stopPropagation();
|
|
202
|
+
|
|
203
|
+
// Store initially selected items
|
|
204
|
+
initiallySelectedItems = new Set(Array.from(container.querySelectorAll('.bg-\\[hsl\\(var\\(--light-green\\)\\)\\]'))
|
|
205
|
+
.map(el => el.closest('.item-container')?.getAttribute('data-item-id'))
|
|
206
|
+
.filter((id): id is string => id !== null));
|
|
207
|
+
|
|
208
|
+
// Store initial scroll position
|
|
209
|
+
scrollStartY = container.scrollTop || 0;
|
|
210
|
+
|
|
211
|
+
// Get mouse position relative to the scroll container
|
|
212
|
+
const scrollRect = scrollContainer?.getBoundingClientRect() || container.getBoundingClientRect();
|
|
213
|
+
|
|
214
|
+
// Calculate the starting position relative to scroll container
|
|
215
|
+
startX = e.clientX - scrollRect.left;
|
|
216
|
+
startY = e.clientY - scrollRect.top;
|
|
217
|
+
|
|
218
|
+
// Log the initial position for debugging
|
|
219
|
+
if(showLogs) console.log('Mouse down position:', {
|
|
220
|
+
clientX: e.clientX,
|
|
221
|
+
clientY: e.clientY,
|
|
222
|
+
scrollRect: {
|
|
223
|
+
left: scrollRect.left,
|
|
224
|
+
top: scrollRect.top
|
|
225
|
+
},
|
|
226
|
+
startX,
|
|
227
|
+
startY,
|
|
228
|
+
scrollStartY
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
// Initialize current position
|
|
232
|
+
currentX = startX;
|
|
233
|
+
currentY = startY;
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
const handleMouseMove = (e: MouseEvent) => {
|
|
237
|
+
// Immediately return if a modal is open
|
|
238
|
+
if (modalOpen) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if (!enabled || !mouseIsDown) return;
|
|
243
|
+
|
|
244
|
+
// Prevent default behavior and stop propagation
|
|
245
|
+
e.preventDefault();
|
|
246
|
+
e.stopPropagation();
|
|
247
|
+
|
|
248
|
+
// Get current scroll positions
|
|
249
|
+
const currentScrollTop = container.scrollTop || 0;
|
|
250
|
+
|
|
251
|
+
// Get mouse position relative to the scroll container
|
|
252
|
+
const scrollRect = scrollContainer?.getBoundingClientRect() || container.getBoundingClientRect();
|
|
253
|
+
|
|
254
|
+
// Update current positions relative to scroll container
|
|
255
|
+
currentX = e.clientX - scrollRect.left;
|
|
256
|
+
currentY = e.clientY - scrollRect.top;
|
|
257
|
+
|
|
258
|
+
// Check if the mouse is within the scroll container
|
|
259
|
+
if (scrollContainer) {
|
|
260
|
+
const scrollRect = scrollContainer.getBoundingClientRect();
|
|
261
|
+
// If mouse is outside the scroll container, don't update the selection
|
|
262
|
+
if (
|
|
263
|
+
e.clientX < scrollRect.left ||
|
|
264
|
+
e.clientX > scrollRect.right ||
|
|
265
|
+
e.clientY < scrollRect.top ||
|
|
266
|
+
e.clientY > scrollRect.bottom
|
|
267
|
+
) {
|
|
268
|
+
// Still allow auto-scrolling when near the edges
|
|
269
|
+
if (isDragging) {
|
|
270
|
+
startAutoScroll();
|
|
271
|
+
}
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// Calculate distance moved
|
|
277
|
+
const distanceX = Math.abs(currentX - startX);
|
|
278
|
+
const distanceY = Math.abs(currentY - startY);
|
|
279
|
+
const distance = Math.sqrt(distanceX * distanceX + distanceY * distanceY);
|
|
280
|
+
if (showLogs && mouseIsDown) {
|
|
281
|
+
console.log(`Mouse move distance: ${distance.toFixed(2)}px`);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// Check if we've moved enough to start dragging
|
|
285
|
+
if (!hasMovedEnough && distance >= DRAG_DISTANCE_THRESHOLD) {
|
|
286
|
+
hasMovedEnough = true;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// Only start dragging if we've moved enough and enough time has passed
|
|
290
|
+
if (!isDragging && hasMovedEnough && Date.now() - dragStartTime >= DRAG_TIME_THRESHOLD) {
|
|
291
|
+
isDragging = true;
|
|
292
|
+
if (showLogs) console.log('Dragging started');
|
|
293
|
+
// Clear any text selection that might have occurred
|
|
294
|
+
window.getSelection()?.removeAllRanges();
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
if (isDragging) {
|
|
298
|
+
updateSelectionBox();
|
|
299
|
+
checkIntersections();
|
|
300
|
+
startAutoScroll();
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
const handleMouseUp = (e: MouseEvent) => {
|
|
305
|
+
// Immediately return if a modal is open
|
|
306
|
+
if (modalOpen) {
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
if (!enabled) return;
|
|
311
|
+
|
|
312
|
+
const wasDragging = isDragging;
|
|
313
|
+
|
|
314
|
+
// If we were dragging, prevent default behavior and stop propagation
|
|
315
|
+
if (wasDragging) {
|
|
316
|
+
e.preventDefault();
|
|
317
|
+
e.stopPropagation();
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
mouseIsDown = false;
|
|
321
|
+
isDragging = false;
|
|
322
|
+
|
|
323
|
+
// Hide the selection box
|
|
324
|
+
resetSelectionBox();
|
|
325
|
+
|
|
326
|
+
stopAutoScroll();
|
|
327
|
+
|
|
328
|
+
// If a drag operation just finished, we need to prevent the browser's
|
|
329
|
+
// subsequent 'click' event from reaching the underlying item. This
|
|
330
|
+
// prevents a race condition where our selection is immediately toggled off.
|
|
331
|
+
if (wasDragging) {
|
|
332
|
+
const blockClick = (clickEvent: MouseEvent) => {
|
|
333
|
+
clickEvent.stopPropagation();
|
|
334
|
+
clickEvent.preventDefault();
|
|
335
|
+
window.removeEventListener('click', blockClick, true);
|
|
336
|
+
};
|
|
337
|
+
window.addEventListener('click', blockClick, true);
|
|
338
|
+
setTimeout(() => window.removeEventListener('click', blockClick, true), 10);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
// Get all selected IDs from the persistent store
|
|
342
|
+
const alreadySelectedInStore = persistentSelectStore.getSelected(currentFilter);
|
|
343
|
+
if(showLogs) console.log(`Store has ${alreadySelectedInStore.length} items already selected:`, alreadySelectedInStore);
|
|
344
|
+
|
|
345
|
+
if (showLogs) {
|
|
346
|
+
console.log('[handleMouseUp] State:', {
|
|
347
|
+
isDragging,
|
|
348
|
+
hasMovedEnough,
|
|
349
|
+
startItemId,
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
// Collect all selected items
|
|
354
|
+
const allSelectedItems: FileSystemItem[] = [];
|
|
355
|
+
const newlySelectedItems: FileSystemItem[] = [];
|
|
356
|
+
|
|
357
|
+
// Get items that are visually selected (have hover-effect class)
|
|
358
|
+
const selectedElements = container.querySelectorAll('.item-container.hover-effect');
|
|
359
|
+
if(showLogs) console.log(`Found ${selectedElements.length} elements with hover-effect`);
|
|
360
|
+
|
|
361
|
+
const selectedElementIdsForCheck = new Set(Array.from(selectedElements).map(el => el.getAttribute('data-item-id')).filter(Boolean) as string[]);
|
|
362
|
+
|
|
363
|
+
// If the drag started on an item and only that item is selected,
|
|
364
|
+
// we assume it's a click-like gesture and let the item's own handler manage it.
|
|
365
|
+
// This prevents a race condition between DragSelect and the item's click handler.
|
|
366
|
+
if (isDragging && startItemId && selectedElementIdsForCheck.size === 1 && selectedElementIdsForCheck.has(startItemId)) {
|
|
367
|
+
if (showLogs) console.log(`Detected single-item drag on item ${startItemId}. Skipping dispatch to avoid conflict.`);
|
|
368
|
+
|
|
369
|
+
// Even though we skip dispatch, we must clean up state.
|
|
370
|
+
mouseIsDown = false;
|
|
371
|
+
isDragging = false;
|
|
372
|
+
resetSelectionBox();
|
|
373
|
+
stopAutoScroll();
|
|
374
|
+
|
|
375
|
+
// Remove hover effect from all items
|
|
376
|
+
container.querySelectorAll('.hover-effect').forEach(element => {
|
|
377
|
+
element.classList.remove('hover-effect');
|
|
378
|
+
element.classList.remove('recent-file-selected');
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
// Reset flags
|
|
382
|
+
hasMovedEnough = false;
|
|
383
|
+
startItemId = null;
|
|
384
|
+
selectedItemIds.clear();
|
|
385
|
+
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
// Debug log the selectedItemIds set vs visually selected elements
|
|
390
|
+
if(showLogs) console.log(`selectedItemIds set has ${selectedItemIds.size} items`);
|
|
391
|
+
|
|
392
|
+
// Collect IDs from visually selected elements
|
|
393
|
+
const selectedElementIds = new Set<string>();
|
|
394
|
+
selectedElements.forEach(element => {
|
|
395
|
+
const itemId = element.getAttribute('data-item-id');
|
|
396
|
+
if (itemId) {
|
|
397
|
+
selectedElementIds.add(itemId);
|
|
398
|
+
|
|
399
|
+
// Log the element info for debugging
|
|
400
|
+
const isRecentFile = element.closest('.recent-files-container') !== null;
|
|
401
|
+
const isAlreadySelected = element.classList.contains('bg-[hsl(var(--light-green))]') ||
|
|
402
|
+
alreadySelectedInStore.includes(itemId);
|
|
403
|
+
if(showLogs) console.log(`Selected element: id=${itemId}, isRecentFile=${isRecentFile}, isAlreadySelected=${isAlreadySelected}`);
|
|
404
|
+
}
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
// Also check for elements with the background color class (already selected)
|
|
408
|
+
const alreadySelectedElements = container.querySelectorAll('.item-container.bg-\\[hsl\\(var\\(--light-green\\)\\)\\]');
|
|
409
|
+
if(showLogs) console.log(`Found ${alreadySelectedElements.length} elements with green background (already selected)`);
|
|
410
|
+
|
|
411
|
+
// Add already selected IDs to our list
|
|
412
|
+
alreadySelectedElements.forEach(element => {
|
|
413
|
+
const itemId = element.getAttribute('data-item-id');
|
|
414
|
+
if (itemId && !selectedElementIds.has(itemId)) {
|
|
415
|
+
selectedElementIds.add(itemId);
|
|
416
|
+
|
|
417
|
+
const isRecentFile = element.closest('.recent-files-container') !== null;
|
|
418
|
+
if(showLogs) console.log(`Already selected element: id=${itemId}, isRecentFile=${isRecentFile}`);
|
|
419
|
+
}
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
// Create a map of item IDs for faster lookup
|
|
423
|
+
const itemsMap = new Map<string, FileSystemItem>();
|
|
424
|
+
items.forEach(item => itemsMap.set(item.id, item));
|
|
425
|
+
|
|
426
|
+
// Track missing items to try a fallback approach
|
|
427
|
+
const missingItemIds = new Set<string>();
|
|
428
|
+
|
|
429
|
+
// Find matching items in our items list
|
|
430
|
+
if (selectedElementIds.size > 0) {
|
|
431
|
+
selectedElementIds.forEach(id => {
|
|
432
|
+
// Try to find the item using the map
|
|
433
|
+
const matchingItem = itemsMap.get(id);
|
|
434
|
+
if (matchingItem) {
|
|
435
|
+
// Add to all selected items list
|
|
436
|
+
allSelectedItems.push(matchingItem);
|
|
437
|
+
|
|
438
|
+
// Only add to newly selected items if it's not already in the store
|
|
439
|
+
if (!alreadySelectedInStore.includes(id)) {
|
|
440
|
+
newlySelectedItems.push(matchingItem);
|
|
441
|
+
}
|
|
442
|
+
} else {
|
|
443
|
+
if(showLogs) console.log(`WARNING: Could not find item with id "${id}" in items list`);
|
|
444
|
+
missingItemIds.add(id);
|
|
445
|
+
}
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
// If we have missing items, try getting them from the DOM
|
|
449
|
+
if (missingItemIds.size > 0) {
|
|
450
|
+
if(showLogs) console.log(`Attempting to extract ${missingItemIds.size} missing items from the DOM`);
|
|
451
|
+
|
|
452
|
+
missingItemIds.forEach(id => {
|
|
453
|
+
// Skip if this ID is already in the store
|
|
454
|
+
if (alreadySelectedInStore.includes(id)) {
|
|
455
|
+
if(showLogs) console.log(`Skipping already selected item: ${id}`);
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
// Find the element in the DOM
|
|
460
|
+
const element = container.querySelector(`.item-container[data-item-id="${id}"]`);
|
|
461
|
+
if (element) {
|
|
462
|
+
// Try to extract data from the DOM element
|
|
463
|
+
const nameElement = element.querySelector('.item-name, .file-name');
|
|
464
|
+
const name = nameElement ? nameElement.textContent?.trim() || id : id;
|
|
465
|
+
|
|
466
|
+
// Determine if it's in recent files section
|
|
467
|
+
const isRecentFile = element.closest('.recent-files-container') !== null;
|
|
468
|
+
|
|
469
|
+
// Create a synthetic item with enough info to be useful
|
|
470
|
+
const syntheticItem: FileSystemItem = {
|
|
471
|
+
id,
|
|
472
|
+
name,
|
|
473
|
+
type: 'file', // Assuming it's a file, not a folder
|
|
474
|
+
url: '',
|
|
475
|
+
size: 0,
|
|
476
|
+
modified: new Date().toISOString()
|
|
477
|
+
};
|
|
478
|
+
|
|
479
|
+
// Log info for debugging
|
|
480
|
+
if(showLogs) console.log(`Created synthetic item from DOM:`, syntheticItem, `(isRecentFile: ${isRecentFile})`);
|
|
481
|
+
|
|
482
|
+
// Add to both lists
|
|
483
|
+
allSelectedItems.push(syntheticItem);
|
|
484
|
+
newlySelectedItems.push(syntheticItem);
|
|
485
|
+
}
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
if(showLogs) console.log('Selection complete, found items:', allSelectedItems.length, 'out of', selectedElementIds.size, 'selected elements');
|
|
491
|
+
if(showLogs) console.log('Newly selected items:', newlySelectedItems.length);
|
|
492
|
+
|
|
493
|
+
// One final check to ensure newlySelectedItems doesn't contain any already selected items
|
|
494
|
+
const finalNewlySelectedItems = newlySelectedItems.filter(item => {
|
|
495
|
+
const isAlreadySelected = alreadySelectedInStore.includes(item.id);
|
|
496
|
+
if (isAlreadySelected) {
|
|
497
|
+
if(showLogs) console.log(`Filtering out already selected item ${item.id} from final selection`);
|
|
498
|
+
}
|
|
499
|
+
return !isAlreadySelected;
|
|
500
|
+
});
|
|
501
|
+
|
|
502
|
+
if (finalNewlySelectedItems.length > 0) {
|
|
503
|
+
if(showLogs) console.log(`Dispatching ${finalNewlySelectedItems.length} newly selected items:`, finalNewlySelectedItems.map(item => item.id));
|
|
504
|
+
|
|
505
|
+
dispatch('select', {
|
|
506
|
+
added: finalNewlySelectedItems, // Only include items that weren't already selected
|
|
507
|
+
removed: []
|
|
508
|
+
});
|
|
509
|
+
} else {
|
|
510
|
+
if(showLogs) console.log('No new items to add to selection after final check');
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
// Cleanup: Only remove hover-effect class but preserve selected states
|
|
514
|
+
container.querySelectorAll('.hover-effect').forEach(element => {
|
|
515
|
+
// Always remove hover effect
|
|
516
|
+
element.classList.remove('hover-effect');
|
|
517
|
+
|
|
518
|
+
// But only remove recent-file-selected class for items that aren't selected
|
|
519
|
+
const itemId = element.getAttribute('data-item-id');
|
|
520
|
+
const isAlreadySelected = element.classList.contains('bg-[hsl(var(--light-green))]') ||
|
|
521
|
+
(itemId && alreadySelectedInStore.includes(itemId));
|
|
522
|
+
|
|
523
|
+
if (!isAlreadySelected) {
|
|
524
|
+
element.classList.remove('recent-file-selected');
|
|
525
|
+
}
|
|
526
|
+
});
|
|
527
|
+
|
|
528
|
+
// Reset flags
|
|
529
|
+
hasMovedEnough = false;
|
|
530
|
+
startItemId = null;
|
|
531
|
+
selectedItemIds.clear();
|
|
532
|
+
};
|
|
533
|
+
|
|
534
|
+
// Use capture phase to intercept events before they reach other handlers
|
|
535
|
+
window.addEventListener('mousedown', handleMouseDown, true);
|
|
536
|
+
window.addEventListener('mousemove', handleMouseMove, true);
|
|
537
|
+
window.addEventListener('mouseup', handleMouseUp, true);
|
|
538
|
+
|
|
539
|
+
return () => {
|
|
540
|
+
window.removeEventListener('mousedown', handleMouseDown, true);
|
|
541
|
+
window.removeEventListener('mousemove', handleMouseMove, true);
|
|
542
|
+
window.removeEventListener('mouseup', handleMouseUp, true);
|
|
543
|
+
stopAutoScroll();
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
// Disable drag select when modal is open
|
|
548
|
+
$: if (modalOpen) {
|
|
549
|
+
mouseIsDown = false;
|
|
550
|
+
isDragging = false;
|
|
551
|
+
if (selectionBox) {
|
|
552
|
+
selectionBox.style.display = 'none';
|
|
553
|
+
}
|
|
554
|
+
stopAutoScroll();
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
// Watch for container changes and reinitialize if needed
|
|
558
|
+
$: if (container) {
|
|
559
|
+
if(showLogs) console.log('Container changed, reinitializing DragSelect');
|
|
560
|
+
|
|
561
|
+
if (cleanup) cleanup();
|
|
562
|
+
|
|
563
|
+
cleanup = initializeEventListeners();
|
|
564
|
+
|
|
565
|
+
// Add keyboard event listener for Escape key
|
|
566
|
+
window.addEventListener('keydown', handleKeyDown);
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
onMount(() => {
|
|
570
|
+
if(showLogs) console.log('DragSelect mounted:', {
|
|
571
|
+
container: !!container,
|
|
572
|
+
enabled,
|
|
573
|
+
itemsCount: items.length,
|
|
574
|
+
hasScrollContainer: !!scrollContainer
|
|
575
|
+
});
|
|
576
|
+
|
|
577
|
+
// Add keyboard event listener for Escape key
|
|
578
|
+
window.addEventListener('keydown', handleKeyDown);
|
|
579
|
+
|
|
580
|
+
// onDestroy alternative
|
|
581
|
+
return () => {
|
|
582
|
+
if (cleanup) {
|
|
583
|
+
cleanup();
|
|
584
|
+
cleanup = null;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
// Remove keyboard event listener
|
|
588
|
+
window.removeEventListener('keydown', handleKeyDown);
|
|
589
|
+
|
|
590
|
+
// Clean up the selection box when component is destroyed
|
|
591
|
+
if (selectionBox && selectionBox.parentNode) {
|
|
592
|
+
selectionBox.parentNode.removeChild(selectionBox);
|
|
593
|
+
selectionBoxInitialized = false;
|
|
594
|
+
}
|
|
595
|
+
};
|
|
596
|
+
});
|
|
597
|
+
|
|
598
|
+
function updateSelectionBox() {
|
|
599
|
+
if (!selectionBox || !container) {
|
|
600
|
+
if(showLogs) console.log('Selection box or container not found');
|
|
601
|
+
return;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
// Calculate selection box coordinates
|
|
605
|
+
let left = Math.min(startX, currentX);
|
|
606
|
+
let top = Math.min(startY, currentY);
|
|
607
|
+
let width = Math.abs(currentX - startX);
|
|
608
|
+
let height = Math.abs(currentY - startY);
|
|
609
|
+
|
|
610
|
+
// Constrain coordinates to scroll container boundaries
|
|
611
|
+
if (scrollContainer) {
|
|
612
|
+
const scrollRect = scrollContainer.getBoundingClientRect();
|
|
613
|
+
const containerRect = container.getBoundingClientRect();
|
|
614
|
+
|
|
615
|
+
// Calculate scroll container bounds
|
|
616
|
+
const scrollLeft = 0;
|
|
617
|
+
const scrollTop = 0;
|
|
618
|
+
const scrollRight = scrollRect.width;
|
|
619
|
+
const scrollBottom = scrollRect.height;
|
|
620
|
+
|
|
621
|
+
// Constrain the selection box to the scroll container
|
|
622
|
+
left = Math.max(left, scrollLeft);
|
|
623
|
+
top = Math.max(top, scrollTop);
|
|
624
|
+
width = Math.min(width, scrollRight - left);
|
|
625
|
+
height = Math.min(height, scrollBottom - top);
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
// Apply the calculated position and dimensions
|
|
629
|
+
selectionBox.style.display = 'block';
|
|
630
|
+
selectionBox.style.left = `${left}px`;
|
|
631
|
+
selectionBox.style.top = `${top}px`;
|
|
632
|
+
selectionBox.style.width = `${width}px`;
|
|
633
|
+
selectionBox.style.height = `${height}px`;
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
function checkIntersections() {
|
|
637
|
+
if (!selectionBox || !container) {
|
|
638
|
+
if(showLogs) console.log('Selection box or container not found');
|
|
639
|
+
return;
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
// Get all selected file IDs from the persistent store
|
|
643
|
+
const alreadySelectedInStore = persistentSelectStore.getSelected(currentFilter);
|
|
644
|
+
|
|
645
|
+
const selectionRect = selectionBox.getBoundingClientRect();
|
|
646
|
+
const containerRect = container.getBoundingClientRect();
|
|
647
|
+
let intersectionCount = 0;
|
|
648
|
+
|
|
649
|
+
// Only check items within the container
|
|
650
|
+
container.querySelectorAll('.item-container').forEach((element) => {
|
|
651
|
+
const itemRect = element.getBoundingClientRect();
|
|
652
|
+
const itemId = element.getAttribute('data-item-id');
|
|
653
|
+
if (!itemId) return;
|
|
654
|
+
|
|
655
|
+
// Check if this is in the Recent Files section
|
|
656
|
+
const isInRecentFiles = element.closest('.recent-files-container') !== null;
|
|
657
|
+
|
|
658
|
+
// Skip if this is a folder (folders have a button with background-color: #FFFFFF)
|
|
659
|
+
// But don't skip if it's in the Recent Files section (since we know those are all files)
|
|
660
|
+
const isFolder = !isInRecentFiles && element.querySelector('button[style*="background-color: #FFFFFF"]') !== null;
|
|
661
|
+
if (isFolder) return;
|
|
662
|
+
|
|
663
|
+
// Check if it's already selected in the persistentSelectStore
|
|
664
|
+
const isSelectedInStore = alreadySelectedInStore.includes(itemId);
|
|
665
|
+
|
|
666
|
+
// Check if element has selected background
|
|
667
|
+
const hasSelectedClass = element.classList.contains('bg-[hsl(var(--light-green))]');
|
|
668
|
+
|
|
669
|
+
// Calculate intersection with selection box
|
|
670
|
+
const intersectsSelection = !(
|
|
671
|
+
itemRect.right < selectionRect.left ||
|
|
672
|
+
itemRect.left > selectionRect.right ||
|
|
673
|
+
itemRect.bottom < selectionRect.top ||
|
|
674
|
+
itemRect.top > selectionRect.bottom
|
|
675
|
+
);
|
|
676
|
+
|
|
677
|
+
if (intersectsSelection || isSelectedInStore || hasSelectedClass) {
|
|
678
|
+
// If the item intersects with selection OR is already selected, mark it as selected
|
|
679
|
+
intersectionCount++;
|
|
680
|
+
selectedItemIds.add(itemId);
|
|
681
|
+
|
|
682
|
+
// Add visual classes
|
|
683
|
+
element.classList.add('hover-effect');
|
|
684
|
+
element.classList.add('widgetic-radius');
|
|
685
|
+
|
|
686
|
+
// If this is a recent file, add special debug class for visibility
|
|
687
|
+
if (isInRecentFiles) {
|
|
688
|
+
if(showLogs) console.log('Recent file intersected or already selected:', itemId);
|
|
689
|
+
element.classList.add('recent-file-selected');
|
|
690
|
+
}
|
|
691
|
+
} else {
|
|
692
|
+
// Only remove selection if not part of initial selection and not selected in store
|
|
693
|
+
if (!initiallySelectedItems.has(itemId) && !isSelectedInStore && !hasSelectedClass) {
|
|
694
|
+
selectedItemIds.delete(itemId);
|
|
695
|
+
element.classList.remove('hover-effect');
|
|
696
|
+
element.classList.remove('widgetic-radius');
|
|
697
|
+
element.classList.remove('recent-file-selected');
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
});
|
|
701
|
+
|
|
702
|
+
// Log intersection count for debugging (only if dragging to avoid console spam)
|
|
703
|
+
if (isDragging && intersectionCount > 0) {
|
|
704
|
+
if(showLogs) console.log(`Intersecting with ${intersectionCount} items (${selectedItemIds.size} total selected)`);
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
function startAutoScroll() {
|
|
709
|
+
if (!scrollContainer) return;
|
|
710
|
+
|
|
711
|
+
stopAutoScroll(); // Clear any existing interval
|
|
712
|
+
|
|
713
|
+
autoScrollInterval = window.setInterval(() => {
|
|
714
|
+
if (!isDragging || !scrollContainer || !container) return;
|
|
715
|
+
|
|
716
|
+
const containerRect = scrollContainer.getBoundingClientRect();
|
|
717
|
+
const mouseY = currentY + container.getBoundingClientRect().top - (scrollContainer?.scrollTop || 0);
|
|
718
|
+
|
|
719
|
+
// Calculate distances from top and bottom edges
|
|
720
|
+
const distanceFromTop = mouseY - containerRect.top;
|
|
721
|
+
const distanceFromBottom = containerRect.bottom - mouseY;
|
|
722
|
+
|
|
723
|
+
let scrolled = false;
|
|
724
|
+
|
|
725
|
+
// Determine scroll direction and speed
|
|
726
|
+
if (distanceFromTop < SCROLL_THRESHOLD) {
|
|
727
|
+
// Scroll up
|
|
728
|
+
scrollContainer.scrollTop -= SCROLL_SPEED;
|
|
729
|
+
scrolled = true;
|
|
730
|
+
} else if (distanceFromBottom < SCROLL_THRESHOLD) {
|
|
731
|
+
// Scroll down
|
|
732
|
+
scrollContainer.scrollTop += SCROLL_SPEED;
|
|
733
|
+
scrolled = true;
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
// Only check intersections if we actually scrolled
|
|
737
|
+
if (scrolled) {
|
|
738
|
+
checkIntersections();
|
|
739
|
+
}
|
|
740
|
+
}, 16); // ~60fps
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
function stopAutoScroll() {
|
|
744
|
+
if (autoScrollInterval !== null) {
|
|
745
|
+
window.clearInterval(autoScrollInterval);
|
|
746
|
+
autoScrollInterval = null;
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
</script>
|
|
750
|
+
|
|
751
|
+
{#if enabled && container && !modalOpen}
|
|
752
|
+
<!-- svelte-ignore element_invalid_self_closing_tag -->
|
|
753
|
+
<div
|
|
754
|
+
bind:this={selectionBox}
|
|
755
|
+
class="selection-box absolute pointer-events-none bg-[hsl(var(--sage-green))]/20 border border-[hsl(var(--sage-green))]"
|
|
756
|
+
style="display: none; position: absolute;"
|
|
757
|
+
/>
|
|
758
|
+
{/if}
|
|
759
|
+
|
|
760
|
+
<style>
|
|
761
|
+
:global(.selecting) {
|
|
762
|
+
background-color: hsl(var(--light-green)) !important;
|
|
763
|
+
} :global(.hover-effect) {
|
|
764
|
+
background-color: hsl(var(--grey1)) !important;
|
|
765
|
+
border-radius: var(--radius-large) !important;
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
/* Recent file selection styling */
|
|
769
|
+
:global(.recent-file-selected) {
|
|
770
|
+
/* Remove the blue outline */
|
|
771
|
+
position: relative !important;
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
/* Remove the dot indicator in the top-right corner of selected items */
|
|
775
|
+
:global(.recent-file-selected::after) {
|
|
776
|
+
display: none;
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
/* Make hover effect for selected recent files brighter */
|
|
780
|
+
:global(.recent-file-selected.hover-effect) {
|
|
781
|
+
background-color: hsl(var(--light-green)) !important;
|
|
782
|
+
opacity: 0.8;
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
/* Enable text selection in modals */
|
|
786
|
+
:global(.modal-content-inner-container),
|
|
787
|
+
:global(.base-modal-portal),
|
|
788
|
+
:global(.modal-content-root-container),
|
|
789
|
+
:global(.modal-backdrop-container) {
|
|
790
|
+
user-select: text !important;
|
|
791
|
+
-webkit-user-select: text !important;
|
|
792
|
+
-moz-user-select: text !important;
|
|
793
|
+
-ms-user-select: text !important;
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
/* Enable text selection in input fields */
|
|
797
|
+
:global(input),
|
|
798
|
+
:global(textarea),
|
|
799
|
+
:global(select),
|
|
800
|
+
:global([contenteditable="true"]) {
|
|
801
|
+
user-select: text !important;
|
|
802
|
+
-webkit-user-select: text !important;
|
|
803
|
+
-moz-user-select: text !important;
|
|
804
|
+
-ms-user-select: text !important;
|
|
805
|
+
cursor: text !important;
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
/* Make selection box match Mac Finder style */
|
|
809
|
+
.selection-box {
|
|
810
|
+
background-color: rgba(6, 153, 255, 0.1);
|
|
811
|
+
border: 1px solid #0699FF;
|
|
812
|
+
pointer-events: none;
|
|
813
|
+
z-index: 10; /* Ensure this is lower than the control toolbar's z-index of 40 */
|
|
814
|
+
}
|
|
815
|
+
</style>
|