@widgetic/file-browser 0.5.35 → 0.5.36

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