@widgetic/file-browser 0.5.18 → 0.5.19

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 (30) hide show
  1. package/dist/components/core/FileBrowser.svelte +149 -1331
  2. package/dist/components/core/FileUploader.svelte +4 -4
  3. package/dist/components/core/Header.svelte +3 -3
  4. package/dist/components/core/RecentFiles.svelte +7 -43
  5. package/dist/components/items/FileItem.svelte +10 -43
  6. package/dist/components/items/FileItem.svelte.d.ts +1 -0
  7. package/dist/components/items/FolderItem.svelte +4 -12
  8. package/dist/components/items/FolderItem.svelte.d.ts +1 -0
  9. package/dist/components/modals/MoveDialog.svelte +17 -17
  10. package/dist/components/modals/SearchModal.svelte +30 -41
  11. package/dist/components/modals/SelectedFilesModal.svelte +2 -2
  12. package/dist/components/previews/AudioPlayer.svelte +1 -1
  13. package/dist/components/previews/FilePreview.svelte +7 -7
  14. package/dist/components/previews/ImagePreview.svelte +13 -13
  15. package/dist/components/previews/VideoPlayer.svelte +1 -1
  16. package/dist/components/ui/DragSelect.svelte +73 -52
  17. package/dist/components/ui/DropdownMenu.svelte +1 -1
  18. package/dist/components/ui/VirtualList.svelte +20 -10
  19. package/dist/data/demoContent.json +1171 -0
  20. package/dist/stores/fileStore.js +1 -1
  21. package/dist/stores/persistentSelectStore.d.ts +1 -0
  22. package/dist/stores/persistentSelectStore.js +23 -0
  23. package/dist/stores/viewportStore.d.ts +5 -0
  24. package/dist/stores/viewportStore.js +19 -0
  25. package/dist/utils/fileOperations.js +17 -14
  26. package/dist/utils/resolveFileUrl.js +6 -2
  27. package/dist/utils/userUploadsStorage.d.ts +5 -0
  28. package/dist/utils/userUploadsStorage.js +15 -6
  29. package/dist/utils/widgeticUpload.d.ts +1 -0
  30. package/package.json +8 -8
@@ -35,6 +35,41 @@
35
35
  let mouseIsDown = false;
36
36
  let startItemId: string | null = null;
37
37
  let selectionBoxInitialized = false;
38
+
39
+ interface CachedDragItem {
40
+ element: HTMLElement;
41
+ id: string;
42
+ rect: DOMRect;
43
+ isInRecentFiles: boolean;
44
+ isSelectedInStore: boolean;
45
+ hasSelectedClass: boolean;
46
+ }
47
+ let cachedItems: CachedDragItem[] = [];
48
+
49
+ function cacheItems() {
50
+ if (!container) return;
51
+ const alreadySelectedInStore = persistentSelectStore.getSelected(currentFilter);
52
+ const elements = container.querySelectorAll<HTMLElement>('.item-container');
53
+ cachedItems = [];
54
+ elements.forEach((element) => {
55
+ const itemId = element.getAttribute('data-item-id');
56
+ if (!itemId) return;
57
+
58
+ const isInRecentFiles = element.closest('.recent-files-container') !== null;
59
+ const isFolder = !isInRecentFiles && element.querySelector('button[style*="background-color: #FFFFFF"]') !== null;
60
+ if (isFolder) return;
61
+
62
+ cachedItems.push({
63
+ element,
64
+ id: itemId,
65
+ rect: element.getBoundingClientRect(),
66
+ isInRecentFiles,
67
+ isSelectedInStore: alreadySelectedInStore.includes(itemId),
68
+ hasSelectedClass: element.classList.contains('bg-[hsl(var(--light-green))]')
69
+ });
70
+ });
71
+ }
72
+
38
73
  //
39
74
  let showLogs = false;
40
75
 
@@ -115,6 +150,7 @@
115
150
  hasMovedEnough = false;
116
151
  startItemId = null;
117
152
  selectedItemIds.clear();
153
+ cachedItems = [];
118
154
  }
119
155
  }
120
156
 
@@ -278,7 +314,7 @@
278
314
  const distanceY = Math.abs(currentY - startY);
279
315
  const distance = Math.sqrt(distanceX * distanceX + distanceY * distanceY);
280
316
  if (showLogs && mouseIsDown) {
281
- console.log(`Mouse move distance: ${distance.toFixed(2)}px`);
317
+ // console.log(`Mouse move distance: ${distance.toFixed(2)}px`);
282
318
  }
283
319
 
284
320
  // Check if we've moved enough to start dragging
@@ -289,6 +325,7 @@
289
325
  // Only start dragging if we've moved enough and enough time has passed
290
326
  if (!isDragging && hasMovedEnough && Date.now() - dragStartTime >= DRAG_TIME_THRESHOLD) {
291
327
  isDragging = true;
328
+ cacheItems();
292
329
  if (showLogs) console.log('Dragging started');
293
330
  // Clear any text selection that might have occurred
294
331
  window.getSelection()?.removeAllRanges();
@@ -343,11 +380,11 @@
343
380
  if(showLogs) console.log(`Store has ${alreadySelectedInStore.length} items already selected:`, alreadySelectedInStore);
344
381
 
345
382
  if (showLogs) {
346
- console.log('[handleMouseUp] State:', {
347
- isDragging,
348
- hasMovedEnough,
349
- startItemId,
350
- });
383
+ // console.log('[handleMouseUp] State:', {
384
+ // isDragging,
385
+ // hasMovedEnough,
386
+ // startItemId,
387
+ // });
351
388
  }
352
389
 
353
390
  // Collect all selected items
@@ -529,6 +566,7 @@
529
566
  hasMovedEnough = false;
530
567
  startItemId = null;
531
568
  selectedItemIds.clear();
569
+ cachedItems = [];
532
570
  };
533
571
 
534
572
  // Use capture phase to intercept events before they reach other handlers
@@ -639,34 +677,17 @@
639
677
  return;
640
678
  }
641
679
 
642
- // Get all selected file IDs from the persistent store
643
- const alreadySelectedInStore = persistentSelectStore.getSelected(currentFilter);
644
-
680
+ if (cachedItems.length === 0) {
681
+ cacheItems();
682
+ }
683
+
645
684
  const selectionRect = selectionBox.getBoundingClientRect();
646
- const containerRect = container.getBoundingClientRect();
647
685
  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
686
+
687
+ for (let i = 0; i < cachedItems.length; i++) {
688
+ const item = cachedItems[i];
689
+ const itemRect = item.rect;
690
+
670
691
  const intersectsSelection = !(
671
692
  itemRect.right < selectionRect.left ||
672
693
  itemRect.left > selectionRect.right ||
@@ -674,31 +695,30 @@
674
695
  itemRect.top > selectionRect.bottom
675
696
  );
676
697
 
677
- if (intersectsSelection || isSelectedInStore || hasSelectedClass) {
678
- // If the item intersects with selection OR is already selected, mark it as selected
698
+ const isMarked = intersectsSelection || item.isSelectedInStore || item.hasSelectedClass;
699
+
700
+ if (isMarked) {
679
701
  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');
702
+ if (!selectedItemIds.has(item.id)) {
703
+ selectedItemIds.add(item.id);
704
+ item.element.classList.add('hover-effect');
705
+ item.element.classList.add('widgetic-radius');
706
+ if (item.isInRecentFiles) {
707
+ item.element.classList.add('recent-file-selected');
708
+ }
690
709
  }
691
710
  } 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');
711
+ if (!initiallySelectedItems.has(item.id) && !item.isSelectedInStore && !item.hasSelectedClass) {
712
+ if (selectedItemIds.has(item.id)) {
713
+ selectedItemIds.delete(item.id);
714
+ item.element.classList.remove('hover-effect');
715
+ item.element.classList.remove('widgetic-radius');
716
+ item.element.classList.remove('recent-file-selected');
717
+ }
698
718
  }
699
719
  }
700
- });
701
-
720
+ }
721
+
702
722
  // Log intersection count for debugging (only if dragging to avoid console spam)
703
723
  if (isDragging && intersectionCount > 0) {
704
724
  if(showLogs) console.log(`Intersecting with ${intersectionCount} items (${selectedItemIds.size} total selected)`);
@@ -735,6 +755,7 @@
735
755
 
736
756
  // Only check intersections if we actually scrolled
737
757
  if (scrolled) {
758
+ cacheItems();
738
759
  checkIntersections();
739
760
  }
740
761
  }, 16); // ~60fps
@@ -29,7 +29,7 @@
29
29
  <Button
30
30
  variant="ghost"
31
31
  class="more-options-button h-6 w-6 p-0 focus-visible:ring-0 focus-visible:ring-offset-0 hover:bg-[hsl(var(--grey1))]"
32
- onclick={() => console.log('Open More Options Dropdown')}
32
+ onclick={() => { /* console.log('Open More Options Dropdown'); */ }}
33
33
  >
34
34
  <span class="sr-only">Open menu</span>
35
35
  <img src={getAssetUrl('/icons/dots.svg')} alt="More options" class="h-4 w-4" />
@@ -34,12 +34,12 @@
34
34
 
35
35
  const updateStart = performance.now();
36
36
  const scrollTop = scrollContainer.scrollTop;
37
- const containerRect = scrollContainer.getBoundingClientRect();
37
+ const containerHeight = scrollContainer.clientHeight;
38
38
 
39
39
  // Calculate visible range based on rows
40
40
  const rowHeight = itemHeight + gap;
41
41
  const startRow = Math.floor(scrollTop / rowHeight);
42
- const visibleRows = Math.ceil(containerRect.height / rowHeight) + 1; // Add one more row for partial visibility
42
+ const visibleRows = Math.ceil(containerHeight / rowHeight) + 1; // Add one more row for partial visibility
43
43
 
44
44
  // Calculate item indices with overscan
45
45
  startIndex = Math.max(0, startRow - overscan) * columns;
@@ -59,19 +59,29 @@
59
59
  dispatch('rangechange', { startIndex, endIndex });
60
60
  }
61
61
 
62
+ let attachedContainer: HTMLElement | null = null;
63
+ $: if (scrollContainer !== attachedContainer) {
64
+ if (attachedContainer) {
65
+ attachedContainer.removeEventListener('scroll', handleScroll);
66
+ }
67
+ attachedContainer = scrollContainer;
68
+ if (attachedContainer) {
69
+ attachedContainer.addEventListener('scroll', handleScroll, { passive: true });
70
+ updateVisibleItems();
71
+ }
72
+ }
73
+
62
74
  function handleScroll() {
63
75
  updateVisibleItems();
64
76
  }
65
77
 
66
78
  onMount(() => {
67
- if (scrollContainer) {
68
- scrollContainer.addEventListener('scroll', handleScroll);
69
- updateVisibleItems();
70
- }
79
+ updateVisibleItems();
71
80
 
72
81
  return () => {
73
- if (scrollContainer) {
74
- scrollContainer.removeEventListener('scroll', handleScroll);
82
+ if (attachedContainer) {
83
+ attachedContainer.removeEventListener('scroll', handleScroll);
84
+ attachedContainer = null;
75
85
  }
76
86
  };
77
87
  });
@@ -79,7 +89,7 @@
79
89
 
80
90
  <div
81
91
  class="{className ? className + ' ' : ''}virtual-list relative flex"
82
- style={style}
92
+ style="height: {totalHeight}px; {style}"
83
93
  bind:this={listElement}
84
94
  >
85
95
  <div
@@ -92,7 +102,7 @@
92
102
  gap: {gap}px;
93
103
  "
94
104
  >
95
- {#each visibleItems as item, i (item.id)}
105
+ {#each visibleItems as item, i (item.id || `${item.type || 'item'}-${startIndex + i}`)}
96
106
  <slot {item} index={startIndex + i} />
97
107
  {/each}
98
108
  </div>