@widgetic/file-browser 0.5.17 → 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 (35) hide show
  1. package/dist/components/FolderTree.svelte.d.ts +1 -2
  2. package/dist/components/core/FileBrowser.svelte +171 -1339
  3. package/dist/components/core/FileUploader.svelte +5 -5
  4. package/dist/components/core/Header.svelte +3 -3
  5. package/dist/components/core/RecentFiles.svelte +7 -43
  6. package/dist/components/items/FileItem.svelte +57 -62
  7. package/dist/components/items/FileItem.svelte.d.ts +1 -0
  8. package/dist/components/items/FolderItem.svelte +4 -12
  9. package/dist/components/items/FolderItem.svelte.d.ts +1 -0
  10. package/dist/components/modals/MoveDialog.svelte +17 -17
  11. package/dist/components/modals/SearchModal.svelte +30 -41
  12. package/dist/components/modals/SelectedFilesModal.svelte +2 -2
  13. package/dist/components/previews/AudioPlayer.svelte +1 -1
  14. package/dist/components/previews/FilePreview.svelte +7 -7
  15. package/dist/components/previews/ImagePreview.svelte +13 -13
  16. package/dist/components/previews/VideoPlayer.svelte +1 -1
  17. package/dist/components/ui/DragSelect.svelte +73 -52
  18. package/dist/components/ui/DropdownMenu.svelte +1 -1
  19. package/dist/components/ui/VirtualList.svelte +20 -10
  20. package/dist/data/demoContent.json +1171 -0
  21. package/dist/stores/fileStore.js +1 -1
  22. package/dist/stores/persistentSelectStore.d.ts +1 -0
  23. package/dist/stores/persistentSelectStore.js +23 -0
  24. package/dist/stores/viewportStore.d.ts +5 -0
  25. package/dist/stores/viewportStore.js +19 -0
  26. package/dist/types.d.ts +1 -0
  27. package/dist/utils/fileOperations.js +17 -14
  28. package/dist/utils/fileUtils.d.ts +7 -0
  29. package/dist/utils/fileUtils.js +22 -0
  30. package/dist/utils/resolveFileUrl.js +6 -2
  31. package/dist/utils/userUploadsStorage.d.ts +5 -0
  32. package/dist/utils/userUploadsStorage.js +16 -6
  33. package/dist/utils/widgeticUpload.d.ts +1 -0
  34. package/dist/utils/widgeticUpload.js +28 -3
  35. package/package.json +8 -8
@@ -144,7 +144,7 @@
144
144
  $: currentIndex = currentFiles.findIndex((f: FileSystemItem) => f.id === file.id);
145
145
 
146
146
  function findNextAvailableFile(startIndex: number, direction: 'next' | 'prev'): FileSystemItem | null {
147
- console.log('Finding next available file from index:', startIndex, 'direction:', direction);
147
+ // console.log('Finding next available file from index:', startIndex, 'direction:', direction);
148
148
  let index = startIndex;
149
149
  const totalFiles = currentFiles.length;
150
150
 
@@ -177,18 +177,18 @@
177
177
 
178
178
  if (event.key === 'ArrowLeft') {
179
179
  event.preventDefault();
180
- console.log('Left arrow pressed, current index:', currentIndex);
180
+ // console.log('Left arrow pressed, current index:', currentIndex);
181
181
  const prevFile = findNextAvailableFile(currentIndex, 'prev');
182
182
  if (prevFile) {
183
- console.log('Navigating to previous file:', prevFile.name);
183
+ // console.log('Navigating to previous file:', prevFile.name);
184
184
  dispatch('navigate', prevFile);
185
185
  }
186
186
  } else if (event.key === 'ArrowRight') {
187
187
  event.preventDefault();
188
- console.log('Right arrow pressed, current index:', currentIndex);
188
+ // console.log('Right arrow pressed, current index:', currentIndex);
189
189
  const nextFile = findNextAvailableFile(currentIndex, 'next');
190
190
  if (nextFile) {
191
- console.log('Navigating to next file:', nextFile.name);
191
+ // console.log('Navigating to next file:', nextFile.name);
192
192
  dispatch('navigate', nextFile);
193
193
  }
194
194
  }
@@ -260,7 +260,7 @@
260
260
  if (videoElement || audioElement) {
261
261
  const mediaElement = videoElement || audioElement;
262
262
  mediaElement.play().catch(error => {
263
- console.log('Autoplay prevented:', error);
263
+ // console.log('Autoplay prevented:', error);
264
264
  // Handle cases where autoplay is blocked by browser policy
265
265
  });
266
266
  }
@@ -436,7 +436,7 @@
436
436
  url={fileUrl}
437
437
  enableCacheClearing={true}
438
438
  on:error={(e) => pdfLoadError = e.detail.message || 'Error loading PDF'}
439
- on:cacheCleared={() => console.log('PDF cache cleared from FilePreview')}
439
+ on:cacheCleared={() => { /* console.log('PDF cache cleared from FilePreview'); */ }}
440
440
  />
441
441
  {:else}
442
442
  <p class="no-preview-container text-center py-8">Preview not available for this file type.</p>
@@ -61,7 +61,7 @@
61
61
 
62
62
  // Subscribe to opacity changes for debugging
63
63
  $: if (debugMode && $containerOpacity !== lastOpacityValue) {
64
- console.log(`[DEBUG] Container opacity changed: ${lastOpacityValue.toFixed(2)} -> ${$containerOpacity.toFixed(2)}, Phase: ${transitionPhase}`);
64
+ // console.log(`[DEBUG] Container opacity changed: ${lastOpacityValue.toFixed(2)} -> ${$containerOpacity.toFixed(2)}, Phase: ${transitionPhase}`);
65
65
  lastOpacityValue = $containerOpacity;
66
66
  logElementStates();
67
67
  }
@@ -70,7 +70,7 @@
70
70
 
71
71
  // Function to clean up any pending image requests
72
72
  function cleanupPreviousImage() {
73
- if (debugMode) console.log(`[DEBUG] Cleaning up previous image, current key: ${imageKey}, new key will be: ${imageKey + 1}`);
73
+ // if (debugMode) console.log(`[DEBUG] Cleaning up previous image, current key: ${imageKey}, new key will be: ${imageKey + 1}`);
74
74
 
75
75
  // Increment the key to force component recreation
76
76
  imageKey++;
@@ -175,7 +175,7 @@
175
175
  if (container) {
176
176
  // Log all image containers
177
177
  const imageContainers = container.querySelectorAll('.image-container');
178
- console.log(`[DEBUG] Found ${imageContainers.length} image containers`);
178
+ // console.log(`[DEBUG] Found ${imageContainers.length} image containers`);
179
179
 
180
180
  imageContainers.forEach((container, index) => {
181
181
  const containerKey = container.getAttribute('data-image-key');
@@ -185,7 +185,7 @@
185
185
  const opacity = getComputedStyle(htmlContainer).opacity;
186
186
  const visibility = getComputedStyle(htmlContainer).visibility;
187
187
 
188
- console.log(`[DEBUG] Container ${index}: key=${containerKey}, src=${containerSrc}, display=${display}, opacity=${opacity}, visibility=${visibility}`);
188
+ // console.log(`[DEBUG] Container ${index}: key=${containerKey}, src=${containerSrc}, display=${display}, opacity=${opacity}, visibility=${visibility}`);
189
189
 
190
190
  // Log thumbhash and main image states
191
191
  const thumbhashImg = container.querySelector('img[data-thumbhash]') as HTMLImageElement;
@@ -199,10 +199,10 @@
199
199
  `visible: ${!!(mainImg.offsetWidth || mainImg.offsetHeight)}, opacity: ${getComputedStyle(mainImg).opacity}, display: ${getComputedStyle(mainImg).display}` :
200
200
  'not found';
201
201
 
202
- console.log(`[DEBUG] Container ${index} images:
203
- - Thumbhash: ${thumbhashState}
204
- - Main Image: ${mainImgState}
205
- `);
202
+ // console.log(`[DEBUG] Container ${index} images:
203
+ // - Thumbhash: ${thumbhashState}
204
+ // - Main Image: ${mainImgState}
205
+ // `);
206
206
  });
207
207
 
208
208
  elementStates.push({
@@ -229,7 +229,7 @@
229
229
  if (img && img.complete && img.naturalWidth > 0) {
230
230
  updateDimensions(img.naturalWidth, img.naturalHeight);
231
231
  imgElement = img;
232
- if (debugMode) console.log(`[DEBUG] Found main image element, dimensions: ${img.naturalWidth}x${img.naturalHeight}`);
232
+ // if (debugMode) console.log(`[DEBUG] Found main image element, dimensions: ${img.naturalWidth}x${img.naturalHeight}`);
233
233
  }
234
234
  }
235
235
  }
@@ -247,14 +247,14 @@
247
247
  for (const mutation of mutations) {
248
248
  if (mutation.type === 'childList') {
249
249
  if (mutation.addedNodes.length > 0) {
250
- console.log(`[DEBUG] DOM nodes added:`, Array.from(mutation.addedNodes).map(node => node.nodeName));
250
+ // console.log(`[DEBUG] DOM nodes added:`, Array.from(mutation.addedNodes).map(node => node.nodeName));
251
251
  }
252
252
  if (mutation.removedNodes.length > 0) {
253
- console.log(`[DEBUG] DOM nodes removed:`, Array.from(mutation.removedNodes).map(node => node.nodeName));
253
+ // console.log(`[DEBUG] DOM nodes removed:`, Array.from(mutation.removedNodes).map(node => node.nodeName));
254
254
  }
255
255
  } else if (mutation.type === 'attributes') {
256
256
  const target = mutation.target as HTMLElement;
257
- console.log(`[DEBUG] Attribute changed: ${mutation.attributeName} on ${target.nodeName}${target.id ? '#'+target.id : ''}, new value: ${target.getAttribute(mutation.attributeName || '')}`);
257
+ // console.log(`[DEBUG] Attribute changed: ${mutation.attributeName} on ${target.nodeName}${target.id ? '#'+target.id : ''}, new value: ${target.getAttribute(mutation.attributeName || '')}`);
258
258
  }
259
259
  logElementStates();
260
260
  }
@@ -267,7 +267,7 @@
267
267
  attributeFilter: ['style', 'class', 'data-thumbhash', 'data-image-key']
268
268
  });
269
269
 
270
- console.log(`[DEBUG] DOM observer set up`);
270
+ // console.log(`[DEBUG] DOM observer set up`);
271
271
  }
272
272
  }
273
273
 
@@ -63,7 +63,7 @@
63
63
  isPlaying = !mediaElement.paused;
64
64
 
65
65
  if (!isPlaying) {
66
- console.log('Autoplay was blocked by the browser');
66
+ // console.log('Autoplay was blocked by the browser');
67
67
  }
68
68
  }
69
69
  }
@@ -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>