@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.
Files changed (319) hide show
  1. package/README.md +131 -0
  2. package/dist/components/FolderTree.svelte +143 -0
  3. package/dist/components/FolderTree.svelte.d.ts +32 -0
  4. package/dist/components/core/FileBrowser.css +79 -0
  5. package/dist/components/core/FileBrowser.svelte +3989 -0
  6. package/dist/components/core/FileBrowser.svelte.d.ts +55 -0
  7. package/dist/components/core/FileUploader.svelte +1152 -0
  8. package/dist/components/core/FileUploader.svelte.d.ts +43 -0
  9. package/dist/components/core/Header.svelte +143 -0
  10. package/dist/components/core/Header.svelte.d.ts +36 -0
  11. package/dist/components/core/RecentFiles.svelte +753 -0
  12. package/dist/components/core/RecentFiles.svelte.d.ts +37 -0
  13. package/dist/components/core/UploadStatus.svelte +133 -0
  14. package/dist/components/core/UploadStatus.svelte.d.ts +28 -0
  15. package/dist/components/core/UploadStatusList.svelte +138 -0
  16. package/dist/components/core/UploadStatusList.svelte.d.ts +33 -0
  17. package/dist/components/core/index.d.ts +4 -0
  18. package/dist/components/core/index.js +4 -0
  19. package/dist/components/index.d.ts +6 -0
  20. package/dist/components/index.js +8 -0
  21. package/dist/components/items/FileItem.svelte +684 -0
  22. package/dist/components/items/FileItem.svelte.d.ts +34 -0
  23. package/dist/components/items/FolderItem.svelte +77 -0
  24. package/dist/components/items/FolderItem.svelte.d.ts +27 -0
  25. package/dist/components/items/index.d.ts +2 -0
  26. package/dist/components/items/index.js +2 -0
  27. package/dist/components/modals/MoveDialog.svelte +539 -0
  28. package/dist/components/modals/MoveDialog.svelte.d.ts +32 -0
  29. package/dist/components/modals/NewFolderButton.svelte +25 -0
  30. package/dist/components/modals/NewFolderButton.svelte.d.ts +20 -0
  31. package/dist/components/modals/README.md +99 -0
  32. package/dist/components/modals/SearchModal.svelte +500 -0
  33. package/dist/components/modals/SearchModal.svelte.d.ts +28 -0
  34. package/dist/components/modals/SelectedFilesModal.svelte +291 -0
  35. package/dist/components/modals/SelectedFilesModal.svelte.d.ts +32 -0
  36. package/dist/components/modals/index.d.ts +6 -0
  37. package/dist/components/modals/index.js +9 -0
  38. package/dist/components/previews/AudioPlayer.svelte +117 -0
  39. package/dist/components/previews/AudioPlayer.svelte.d.ts +22 -0
  40. package/dist/components/previews/ErrorPreview.svelte +12 -0
  41. package/dist/components/previews/ErrorPreview.svelte.d.ts +20 -0
  42. package/dist/components/previews/FilePreview.svelte +475 -0
  43. package/dist/components/previews/FilePreview.svelte.d.ts +31 -0
  44. package/dist/components/previews/FontPreview.svelte +82 -0
  45. package/dist/components/previews/FontPreview.svelte.d.ts +22 -0
  46. package/dist/components/previews/ImagePreview.svelte +551 -0
  47. package/dist/components/previews/ImagePreview.svelte.d.ts +27 -0
  48. package/dist/components/previews/TextPreview.svelte +92 -0
  49. package/dist/components/previews/TextPreview.svelte.d.ts +20 -0
  50. package/dist/components/previews/VideoPlayer.svelte +268 -0
  51. package/dist/components/previews/VideoPlayer.svelte.d.ts +22 -0
  52. package/dist/components/previews/WaveformVisualizer.svelte +240 -0
  53. package/dist/components/previews/WaveformVisualizer.svelte.d.ts +20 -0
  54. package/dist/components/previews/index.d.ts +8 -0
  55. package/dist/components/previews/index.js +8 -0
  56. package/dist/components/ui/ControlToolbar.svelte +342 -0
  57. package/dist/components/ui/ControlToolbar.svelte.d.ts +36 -0
  58. package/dist/components/ui/DragSelect.svelte +815 -0
  59. package/dist/components/ui/DragSelect.svelte.d.ts +31 -0
  60. package/dist/components/ui/DropdownMenu.svelte +83 -0
  61. package/dist/components/ui/DropdownMenu.svelte.d.ts +25 -0
  62. package/dist/components/ui/FileIcon.svelte +65 -0
  63. package/dist/components/ui/FileIcon.svelte.d.ts +25 -0
  64. package/dist/components/ui/FileMetadata.svelte +26 -0
  65. package/dist/components/ui/FileMetadata.svelte.d.ts +21 -0
  66. package/dist/components/ui/LoadingSkeleton.svelte +26 -0
  67. package/dist/components/ui/LoadingSkeleton.svelte.d.ts +22 -0
  68. package/dist/components/ui/SearchResults.svelte +37 -0
  69. package/dist/components/ui/SearchResults.svelte.d.ts +21 -0
  70. package/dist/components/ui/VirtualList.svelte +106 -0
  71. package/dist/components/ui/VirtualList.svelte.d.ts +45 -0
  72. package/dist/components/ui/index.d.ts +8 -0
  73. package/dist/components/ui/index.js +8 -0
  74. package/dist/config.d.ts +7 -0
  75. package/dist/config.js +14 -0
  76. package/dist/index.d.ts +7 -0
  77. package/dist/index.js +11 -0
  78. package/dist/static/favicon.png +0 -0
  79. package/dist/static/files/audio/audio-file.mp3 +0 -0
  80. package/dist/static/files/document/-missing-file.txt +1 -0
  81. package/dist/static/files/document/HeliosDesign Website Project Brief Sample.pdf +0 -0
  82. package/dist/static/files/document/RFP-NEC_Website-Development_2021-August.pdf +0 -0
  83. package/dist/static/files/document/The World Before Calculus.pdf +0 -0
  84. package/dist/static/files/document/specs.txt +15 -0
  85. package/dist/static/files/font/CooperHewitt/CooperHewitt-Bold.otf +0 -0
  86. package/dist/static/files/font/CooperHewitt/CooperHewitt-BoldItalic.otf +0 -0
  87. package/dist/static/files/font/CooperHewitt/CooperHewitt-Book.otf +0 -0
  88. package/dist/static/files/font/CooperHewitt/CooperHewitt-BookItalic.otf +0 -0
  89. package/dist/static/files/font/CooperHewitt/CooperHewitt-Heavy.otf +0 -0
  90. package/dist/static/files/font/CooperHewitt/CooperHewitt-HeavyItalic.otf +0 -0
  91. package/dist/static/files/font/CooperHewitt/CooperHewitt-Light.otf +0 -0
  92. package/dist/static/files/font/CooperHewitt/CooperHewitt-LightItalic.otf +0 -0
  93. package/dist/static/files/font/CooperHewitt/CooperHewitt-Medium.otf +0 -0
  94. package/dist/static/files/font/CooperHewitt/CooperHewitt-MediumItalic.otf +0 -0
  95. package/dist/static/files/font/CooperHewitt/CooperHewitt-Semibold.otf +0 -0
  96. package/dist/static/files/font/CooperHewitt/CooperHewitt-SemiboldItalic.otf +0 -0
  97. package/dist/static/files/font/CooperHewitt/CooperHewitt-Thin.otf +0 -0
  98. package/dist/static/files/font/CooperHewitt/CooperHewitt-ThinItalic.otf +0 -0
  99. package/dist/static/files/font/Kimpo/Kimpo-Bold.otf +0 -0
  100. package/dist/static/files/font/Kimpo/Kimpo-Regular.otf +0 -0
  101. package/dist/static/files/image/image 1.jpg +0 -0
  102. package/dist/static/files/image/image 10.jpg +0 -0
  103. package/dist/static/files/image/image 11.jpg +0 -0
  104. package/dist/static/files/image/image 12.jpg +0 -0
  105. package/dist/static/files/image/image 13.jpg +0 -0
  106. package/dist/static/files/image/image 14.jpg +0 -0
  107. package/dist/static/files/image/image 15.jpg +0 -0
  108. package/dist/static/files/image/image 16.jpg +0 -0
  109. package/dist/static/files/image/image 17.jpg +0 -0
  110. package/dist/static/files/image/image 18.jpg +0 -0
  111. package/dist/static/files/image/image 19.jpg +0 -0
  112. package/dist/static/files/image/image 2.jpg +0 -0
  113. package/dist/static/files/image/image 20.jpg +0 -0
  114. package/dist/static/files/image/image 21.jpg +0 -0
  115. package/dist/static/files/image/image 22.jpg +0 -0
  116. package/dist/static/files/image/image 23.jpg +0 -0
  117. package/dist/static/files/image/image 24.jpg +0 -0
  118. package/dist/static/files/image/image 25.jpg +0 -0
  119. package/dist/static/files/image/image 26.jpg +0 -0
  120. package/dist/static/files/image/image 27.jpg +0 -0
  121. package/dist/static/files/image/image 28.jpg +0 -0
  122. package/dist/static/files/image/image 29.jpg +0 -0
  123. package/dist/static/files/image/image 3.jpg +0 -0
  124. package/dist/static/files/image/image 30.jpg +0 -0
  125. package/dist/static/files/image/image 31.jpg +0 -0
  126. package/dist/static/files/image/image 32.jpg +0 -0
  127. package/dist/static/files/image/image 33.jpg +0 -0
  128. package/dist/static/files/image/image 34.jpg +0 -0
  129. package/dist/static/files/image/image 35.jpg +0 -0
  130. package/dist/static/files/image/image 36.jpg +0 -0
  131. package/dist/static/files/image/image 37.jpg +0 -0
  132. package/dist/static/files/image/image 38.jpg +0 -0
  133. package/dist/static/files/image/image 39.jpg +0 -0
  134. package/dist/static/files/image/image 4.jpg +0 -0
  135. package/dist/static/files/image/image 40.jpg +0 -0
  136. package/dist/static/files/image/image 41.jpg +0 -0
  137. package/dist/static/files/image/image 42.jpg +0 -0
  138. package/dist/static/files/image/image 43.jpg +0 -0
  139. package/dist/static/files/image/image 44.jpg +0 -0
  140. package/dist/static/files/image/image 45.jpg +0 -0
  141. package/dist/static/files/image/image 46.jpg +0 -0
  142. package/dist/static/files/image/image 47.jpg +0 -0
  143. package/dist/static/files/image/image 48.jpg +0 -0
  144. package/dist/static/files/image/image 49.jpg +0 -0
  145. package/dist/static/files/image/image 5.jpg +0 -0
  146. package/dist/static/files/image/image 50.jpg +0 -0
  147. package/dist/static/files/image/image 51.jpg +0 -0
  148. package/dist/static/files/image/image 52.jpg +0 -0
  149. package/dist/static/files/image/image 53.jpg +0 -0
  150. package/dist/static/files/image/image 54.jpg +0 -0
  151. package/dist/static/files/image/image 55.jpg +0 -0
  152. package/dist/static/files/image/image 56.jpg +0 -0
  153. package/dist/static/files/image/image 57.jpg +0 -0
  154. package/dist/static/files/image/image 58.jpg +0 -0
  155. package/dist/static/files/image/image 59.jpg +0 -0
  156. package/dist/static/files/image/image 6.jpg +0 -0
  157. package/dist/static/files/image/image 60.jpg +0 -0
  158. package/dist/static/files/image/image 61.jpg +0 -0
  159. package/dist/static/files/image/image 62.jpg +0 -0
  160. package/dist/static/files/image/image 63.jpg +0 -0
  161. package/dist/static/files/image/image 64.jpg +0 -0
  162. package/dist/static/files/image/image 65.jpg +0 -0
  163. package/dist/static/files/image/image 66.jpg +0 -0
  164. package/dist/static/files/image/image 67.jpg +0 -0
  165. package/dist/static/files/image/image 68.jpg +0 -0
  166. package/dist/static/files/image/image 7.jpg +0 -0
  167. package/dist/static/files/image/image 8.jpg +0 -0
  168. package/dist/static/files/image/image 9.jpg +0 -0
  169. package/dist/static/files/svg/astronaut.svg +30 -0
  170. package/dist/static/files/svg/cook.svg +30 -0
  171. package/dist/static/files/svg/dj.svg +28 -0
  172. package/dist/static/files/svg/doctor.svg +29 -0
  173. package/dist/static/files/svg/farmer.svg +43 -0
  174. package/dist/static/files/svg/fire fighter.svg +40 -0
  175. package/dist/static/files/svg/plumber.svg +32 -0
  176. package/dist/static/files/svg/santa.svg +34 -0
  177. package/dist/static/files/svg/scientist.svg +31 -0
  178. package/dist/static/files/svg/student.svg +32 -0
  179. package/dist/static/files/thumbnail/image 1.jpg +0 -0
  180. package/dist/static/files/thumbnail/image 10.jpg +0 -0
  181. package/dist/static/files/thumbnail/image 11.jpg +0 -0
  182. package/dist/static/files/thumbnail/image 12.jpg +0 -0
  183. package/dist/static/files/thumbnail/image 13.jpg +0 -0
  184. package/dist/static/files/thumbnail/image 14.jpg +0 -0
  185. package/dist/static/files/thumbnail/image 15.jpg +0 -0
  186. package/dist/static/files/thumbnail/image 16.jpg +0 -0
  187. package/dist/static/files/thumbnail/image 17.jpg +0 -0
  188. package/dist/static/files/thumbnail/image 18.jpg +0 -0
  189. package/dist/static/files/thumbnail/image 19.jpg +0 -0
  190. package/dist/static/files/thumbnail/image 2.jpg +0 -0
  191. package/dist/static/files/thumbnail/image 20.jpg +0 -0
  192. package/dist/static/files/thumbnail/image 21.jpg +0 -0
  193. package/dist/static/files/thumbnail/image 22.jpg +0 -0
  194. package/dist/static/files/thumbnail/image 23.jpg +0 -0
  195. package/dist/static/files/thumbnail/image 24.jpg +0 -0
  196. package/dist/static/files/thumbnail/image 25.jpg +0 -0
  197. package/dist/static/files/thumbnail/image 26.jpg +0 -0
  198. package/dist/static/files/thumbnail/image 27.jpg +0 -0
  199. package/dist/static/files/thumbnail/image 28.jpg +0 -0
  200. package/dist/static/files/thumbnail/image 29.jpg +0 -0
  201. package/dist/static/files/thumbnail/image 3.jpg +0 -0
  202. package/dist/static/files/thumbnail/image 30.jpg +0 -0
  203. package/dist/static/files/thumbnail/image 31.jpg +0 -0
  204. package/dist/static/files/thumbnail/image 32.jpg +0 -0
  205. package/dist/static/files/thumbnail/image 33.jpg +0 -0
  206. package/dist/static/files/thumbnail/image 34.jpg +0 -0
  207. package/dist/static/files/thumbnail/image 35.jpg +0 -0
  208. package/dist/static/files/thumbnail/image 36.jpg +0 -0
  209. package/dist/static/files/thumbnail/image 37.jpg +0 -0
  210. package/dist/static/files/thumbnail/image 38.jpg +0 -0
  211. package/dist/static/files/thumbnail/image 39.jpg +0 -0
  212. package/dist/static/files/thumbnail/image 4.jpg +0 -0
  213. package/dist/static/files/thumbnail/image 40.jpg +0 -0
  214. package/dist/static/files/thumbnail/image 41.jpg +0 -0
  215. package/dist/static/files/thumbnail/image 42.jpg +0 -0
  216. package/dist/static/files/thumbnail/image 43.jpg +0 -0
  217. package/dist/static/files/thumbnail/image 44.jpg +0 -0
  218. package/dist/static/files/thumbnail/image 45.jpg +0 -0
  219. package/dist/static/files/thumbnail/image 46.jpg +0 -0
  220. package/dist/static/files/thumbnail/image 47.jpg +0 -0
  221. package/dist/static/files/thumbnail/image 48.jpg +0 -0
  222. package/dist/static/files/thumbnail/image 49.jpg +0 -0
  223. package/dist/static/files/thumbnail/image 5.jpg +0 -0
  224. package/dist/static/files/thumbnail/image 50.jpg +0 -0
  225. package/dist/static/files/thumbnail/image 51.jpg +0 -0
  226. package/dist/static/files/thumbnail/image 52.jpg +0 -0
  227. package/dist/static/files/thumbnail/image 53.jpg +0 -0
  228. package/dist/static/files/thumbnail/image 54.jpg +0 -0
  229. package/dist/static/files/thumbnail/image 55.jpg +0 -0
  230. package/dist/static/files/thumbnail/image 56.jpg +0 -0
  231. package/dist/static/files/thumbnail/image 57.jpg +0 -0
  232. package/dist/static/files/thumbnail/image 58.jpg +0 -0
  233. package/dist/static/files/thumbnail/image 59.jpg +0 -0
  234. package/dist/static/files/thumbnail/image 6.jpg +0 -0
  235. package/dist/static/files/thumbnail/image 60.jpg +0 -0
  236. package/dist/static/files/thumbnail/image 61.jpg +0 -0
  237. package/dist/static/files/thumbnail/image 62.jpg +0 -0
  238. package/dist/static/files/thumbnail/image 63.jpg +0 -0
  239. package/dist/static/files/thumbnail/image 64.jpg +0 -0
  240. package/dist/static/files/thumbnail/image 65.jpg +0 -0
  241. package/dist/static/files/thumbnail/image 66.jpg +0 -0
  242. package/dist/static/files/thumbnail/image 67.jpg +0 -0
  243. package/dist/static/files/thumbnail/image 68.jpg +0 -0
  244. package/dist/static/files/thumbnail/image 7.jpg +0 -0
  245. package/dist/static/files/thumbnail/image 8.jpg +0 -0
  246. package/dist/static/files/thumbnail/image 9.jpg +0 -0
  247. package/dist/static/files/video/video-file.mp4 +0 -0
  248. package/dist/static/files/video/video-file.png +0 -0
  249. package/dist/static/icons/audio.svg +7 -0
  250. package/dist/static/icons/check.svg +3 -0
  251. package/dist/static/icons/checked.svg +4 -0
  252. package/dist/static/icons/close.svg +11 -0
  253. package/dist/static/icons/document.svg +11 -0
  254. package/dist/static/icons/dots.svg +1 -0
  255. package/dist/static/icons/download.svg +1 -0
  256. package/dist/static/icons/empty-folder.svg +24 -0
  257. package/dist/static/icons/error.svg +5 -0
  258. package/dist/static/icons/file-upload.svg +1 -0
  259. package/dist/static/icons/folder-plus.svg +1 -0
  260. package/dist/static/icons/folder.svg +28 -0
  261. package/dist/static/icons/jump-to-folder.svg +1 -0
  262. package/dist/static/icons/move.svg +1 -0
  263. package/dist/static/icons/new-folder.svg +5 -0
  264. package/dist/static/icons/pdf.svg +6 -0
  265. package/dist/static/icons/player-pause.svg +1 -0
  266. package/dist/static/icons/player-play.svg +3 -0
  267. package/dist/static/icons/plus.svg +1 -0
  268. package/dist/static/icons/rename.svg +1 -0
  269. package/dist/static/icons/search.svg +1 -0
  270. package/dist/static/icons/trash.svg +1 -0
  271. package/dist/static/icons/unorganized-folder.svg +60 -0
  272. package/dist/stores/dragStore.d.ts +2 -0
  273. package/dist/stores/dragStore.js +2 -0
  274. package/dist/stores/fileStore.d.ts +36 -0
  275. package/dist/stores/fileStore.js +166 -0
  276. package/dist/stores/folderCountStore.d.ts +5 -0
  277. package/dist/stores/folderCountStore.js +49 -0
  278. package/dist/stores/index.d.ts +7 -0
  279. package/dist/stores/index.js +8 -0
  280. package/dist/stores/missingFilesStore.d.ts +3 -0
  281. package/dist/stores/missingFilesStore.js +14 -0
  282. package/dist/stores/navigationStore.d.ts +36 -0
  283. package/dist/stores/navigationStore.js +615 -0
  284. package/dist/stores/persistentSelectStore.d.ts +17 -0
  285. package/dist/stores/persistentSelectStore.js +170 -0
  286. package/dist/stores/searchStore.d.ts +1 -0
  287. package/dist/stores/searchStore.js +2 -0
  288. package/dist/stores/uploadApiStore.d.ts +13 -0
  289. package/dist/stores/uploadApiStore.js +36 -0
  290. package/dist/types/index.d.ts +1 -0
  291. package/dist/types/index.js +3 -0
  292. package/dist/types/pdf.d.ts +3 -0
  293. package/dist/types.d.ts +23 -0
  294. package/dist/types.js +1 -0
  295. package/dist/utils/apiConfig.d.ts +9 -0
  296. package/dist/utils/apiConfig.js +19 -0
  297. package/dist/utils/dateUtils.d.ts +2 -0
  298. package/dist/utils/dateUtils.js +38 -0
  299. package/dist/utils/fileOperations.d.ts +36 -0
  300. package/dist/utils/fileOperations.js +573 -0
  301. package/dist/utils/fileTypes.d.ts +17 -0
  302. package/dist/utils/fileTypes.js +110 -0
  303. package/dist/utils/fileUtils.d.ts +15 -0
  304. package/dist/utils/fileUtils.js +112 -0
  305. package/dist/utils/folderUtils.d.ts +4 -0
  306. package/dist/utils/folderUtils.js +26 -0
  307. package/dist/utils/imageTransform.d.ts +22 -0
  308. package/dist/utils/imageTransform.js +60 -0
  309. package/dist/utils/index.d.ts +5 -0
  310. package/dist/utils/index.js +6 -0
  311. package/dist/utils/resolveFileUrl.d.ts +6 -0
  312. package/dist/utils/resolveFileUrl.js +21 -0
  313. package/dist/utils/userUploadsStorage.d.ts +27 -0
  314. package/dist/utils/userUploadsStorage.js +168 -0
  315. package/dist/utils/widgeticTusUpload.d.ts +18 -0
  316. package/dist/utils/widgeticTusUpload.js +131 -0
  317. package/dist/utils/widgeticUpload.d.ts +29 -0
  318. package/dist/utils/widgeticUpload.js +105 -0
  319. package/package.json +156 -0
@@ -0,0 +1,1152 @@
1
+ <script lang="ts">
2
+ // Svelte imports
3
+ import { onMount } from 'svelte';
4
+ import { createEventDispatcher } from 'svelte';
5
+ import { browser } from '$app/environment';
6
+ const dispatch = createEventDispatcher();
7
+
8
+ // Design system imports
9
+ import { Button, Tooltip, Progress, Portal } from '@widgetic/design-system/components';
10
+ import { IconHelp, IconTrash, IconRefresh, IconX, IconChevronDown, IconChevronUp, IconCheck } from '@widgetic/design-system/icons';
11
+
12
+
13
+ // Import toast utility
14
+ import { showToast } from '@widgetic/design-system/components';
15
+
16
+ // Local stores imports
17
+ import { isDraggingFiles } from '../../stores/dragStore';
18
+ import { fileStore } from '../../stores/fileStore';
19
+
20
+ // Local components imports
21
+ // import UploadStatusList from './UploadStatusList.svelte';
22
+
23
+ // Local utils imports
24
+ import { formatAllowedTypesForDisplay, type FileFilterType, FILE_TYPES, getMimeTypeExtension, normalizeFileMimeType } from '../../utils/fileTypes';
25
+ import { get } from 'svelte/store';
26
+ import { fileBrowserUploadConfig } from '../../stores/uploadApiStore';
27
+ import { uploadToWidgeticApi } from '../../utils/widgeticUpload';
28
+ import { getAssetUrl } from '../../utils/fileUtils';
29
+
30
+ // Component props variables
31
+ export let allowedTypes: string[] = [];
32
+ export let currentPath: string[] = [];
33
+ export let filter: FileFilterType = 'all';
34
+ export let restrictDuplicateNames = false;
35
+ export let dragActive = false;
36
+ export let dragInvalid = false;
37
+ export let hasValidFiles = false;
38
+ export let isDraggingFolder = false;
39
+ export let currentFolderId: string = '';
40
+ export let portalTarget: HTMLElement | null = null; // Reference to parent element
41
+
42
+ // Local variables
43
+ let uploading = false;
44
+ let fileInput: HTMLInputElement;
45
+ let uploaderRootEl: HTMLDivElement;
46
+ let mouseX = 0;
47
+ let mouseY = 0;
48
+ // tooltip vars
49
+ let showHelp = false;
50
+ let showCollapseTooltip = false;
51
+ let showCloseTooltip = false;
52
+ // show logs
53
+ let showLogs = false;
54
+
55
+ // Responsive state
56
+ let isSmallScreen = browser ? window.innerWidth <= 768 : false;
57
+
58
+ // Panel state
59
+ let isUploadsModalOpen = false;
60
+ let isUploadsDrawerCollapsed = false;
61
+
62
+ // Upload tracking
63
+ type UploadItem = {
64
+ id: string;
65
+ file: File;
66
+ progress: number;
67
+ status: 'uploading' | 'complete' | 'failed';
68
+ previewUrl: string;
69
+ errorMessage?: string;
70
+ timeRemaining?: string;
71
+ controller?: AbortController;
72
+ };
73
+
74
+ let uploadItems: UploadItem[] = [];
75
+ let uploadInProgress = false;
76
+
77
+ // Reactive variables
78
+ $: allowedTypesText = formatAllowedTypesText(filter === 'all' ? allowedTypes : FILE_TYPES[filter as Exclude<FileFilterType, 'all'>]);
79
+ $: tooltipTypesText = formatAllowedTypesForDisplay(filter);
80
+ $: acceptTypes = filter === 'all'
81
+ ? Object.values(FILE_TYPES).flat().join(',')
82
+ : FILE_TYPES[filter as Exclude<FileFilterType, 'all'>].join(',');
83
+ $: allowedTypesDisplayText = filter === 'all' ? 'any' : allowedTypesText;
84
+ $: showUploader = uploadItems.length === 0;
85
+
86
+ // Calculate overall progress for all uploads
87
+ $: overallProgress = calculateOverallProgress(uploadItems);
88
+
89
+ /* Reactive statements to handle uploads drawer state
90
+ $: {
91
+ // Open panel when new uploads are added
92
+ if (uploadItems.length > 0 && !isUploadsModalOpen) {
93
+ if(showLogs) console.log('Opening drawer due to new uploads');
94
+ setTimeout(() => {
95
+ isUploadsModalOpen = true;
96
+ isUploadsDrawerCollapsed = false;
97
+ }, 0);
98
+ }
99
+ // Close panel when all uploads are cleared
100
+ else if (uploadItems.length === 0 && isUploadsModalOpen) {
101
+ // Add a small delay before closing the drawer to allow for animations
102
+ setTimeout(() => {
103
+ if(showLogs) console.log('Closing drawer due to no uploads');
104
+ isUploadsModalOpen = false;
105
+ }, 300);
106
+ }
107
+ }*/
108
+
109
+ /**
110
+ * Calculates the overall progress of all uploads
111
+ * @param items Array of upload items
112
+ * @returns Progress percentage (0-100)
113
+ */
114
+ function calculateOverallProgress(items: UploadItem[]): number {
115
+ if (items.length === 0) return 0;
116
+
117
+ const totalItems = items.length;
118
+ const completedItems = items.filter(item => item.status === 'complete').length;
119
+ const failedItems = items.filter(item => item.status === 'failed').length;
120
+ const inProgressItems = items.filter(item => item.status === 'uploading');
121
+
122
+ // Calculate progress percentage
123
+ const completedPercentage = (completedItems / totalItems) * 100;
124
+ const inProgressPercentage = inProgressItems.reduce((sum, item) => sum + (item.progress / totalItems), 0);
125
+
126
+ return Math.round(completedPercentage + inProgressPercentage);
127
+ }
128
+
129
+ function isFileTypeAllowed(file: File): boolean {
130
+ const fileExtension = '.' + file.name.split('.').pop()?.toLowerCase();
131
+ return acceptTypes.includes(fileExtension);
132
+ }
133
+
134
+ export function handleDragEnter(e: DragEvent) {
135
+ e.preventDefault();
136
+ e.stopPropagation();
137
+
138
+ dragActive = true;
139
+ }
140
+
141
+ export function handleDragOver(e: DragEvent) {
142
+ e.preventDefault();
143
+ e.stopPropagation();
144
+
145
+ if (e.dataTransfer?.items) {
146
+ const hasInvalidFiles = Array.from(e.dataTransfer.items).some(item => {
147
+ if (item.kind === 'file') {
148
+ if (!item.type) {
149
+ hasValidFiles = false;
150
+ isDraggingFolder = true;
151
+ return true;
152
+ }
153
+
154
+ isDraggingFolder = false;
155
+ const extension = getMimeTypeExtension(item.type);
156
+ const isInvalid = !acceptTypes.includes(extension);
157
+ return isInvalid;
158
+ }
159
+ return false;
160
+ });
161
+
162
+ dragInvalid = hasInvalidFiles;
163
+ hasValidFiles = e.dataTransfer.items.length > 0 && !hasInvalidFiles;
164
+ }
165
+ }
166
+
167
+ export function handleDragLeave(e: DragEvent) {
168
+ e.preventDefault();
169
+ e.stopPropagation();
170
+
171
+ dragActive = false;
172
+ dragInvalid = false;
173
+ hasValidFiles = false;
174
+ }
175
+
176
+ export function handleDrop(e: DragEvent) {
177
+ e.preventDefault();
178
+ e.stopPropagation();
179
+ dragActive = false;
180
+ dragInvalid = false;
181
+
182
+ const files = e.dataTransfer?.files;
183
+ if (files) {
184
+ const hasFolder = Array.from(files).some(file => file.size === 0 && file.type === '');
185
+ if (hasFolder) {
186
+ isDraggingFolder = true;
187
+ dragInvalid = true;
188
+ setTimeout(() => {
189
+ showToast('error', 'Folders cannot be uploaded');
190
+ return;
191
+ }, 0);
192
+ return;
193
+ }
194
+
195
+ isDraggingFolder = false;
196
+ const hasInvalidFiles = Array.from(files).some(file => {
197
+ const extension = file.name.split('.').pop()?.toLowerCase();
198
+ const fileExtension = extension ? '.' + extension : '';
199
+ return !acceptTypes.includes(fileExtension);
200
+ });
201
+
202
+ if (hasInvalidFiles) {
203
+ isDraggingFolder = false;
204
+ dragInvalid = true;
205
+ setTimeout(() => {
206
+ showToast('error', `Invalid file type. Please use ${filter === 'document' ? 'document' : allowedTypesDisplayText} files only.`);
207
+ return;
208
+ }, 0);
209
+ return;
210
+ }
211
+
212
+ dragInvalid = false;
213
+ isDraggingFolder = false;
214
+ handleFiles(files);
215
+ }
216
+ }
217
+
218
+ function handleFileSelect(e: Event) {
219
+ const files = (e.target as HTMLInputElement).files;
220
+ if (files) handleFiles(files);
221
+ }
222
+
223
+ /**
224
+ * Recursively gets all files from a folder structure
225
+ * @param folder Folder to get files from
226
+ * @returns Array of all files in folder and subfolders
227
+ */
228
+ function getAllFiles(folder: any): any[] {
229
+ let files: any[] = [];
230
+ if (folder.children) {
231
+ for (const item of folder.children) {
232
+ if (item.type === 'file') {
233
+ files.push(item);
234
+ } else if (item.type === 'folder') {
235
+ files = files.concat(getAllFiles(item));
236
+ }
237
+ }
238
+ }
239
+ return files;
240
+ }
241
+
242
+ /**
243
+ * Checks if a file with the same name and type already exists
244
+ * @param fileName Name of file to check
245
+ * @param fileExtension File extension to match
246
+ * @returns boolean indicating if file exists
247
+ */
248
+ function isDuplicate(fileName: string, fileExtension: string): boolean {
249
+ const allFiles = getAllFiles($fileStore.root);
250
+ return allFiles.some(file => {
251
+ const existingFileExtension = '.' + file.name.split('.').pop()?.toLowerCase();
252
+ return file.name.toLowerCase() === fileName.toLowerCase() &&
253
+ existingFileExtension === fileExtension.toLowerCase();
254
+ });
255
+ }
256
+
257
+ function addFileToStructure(structure: any, folderId: string, newFile: any): boolean {
258
+ // If this is the target folder
259
+ if (structure.id === folderId) {
260
+ if (!structure.children) {
261
+ structure.children = [];
262
+ }
263
+ structure.children.push(newFile);
264
+ return true;
265
+ }
266
+
267
+ // If this item has children, recursively search them
268
+ if (structure.children) {
269
+ for (const child of structure.children) {
270
+ if (child.type === 'folder') {
271
+ if (addFileToStructure(child, folderId, newFile)) {
272
+ return true;
273
+ }
274
+ }
275
+ }
276
+ }
277
+
278
+ return false;
279
+ }
280
+
281
+ /**
282
+ * Creates a preview URL for a file if possible
283
+ * HEIC/HEIF blobs cannot be decoded by most browsers, so they fall back to the
284
+ * extension placeholder instead of a black image tile.
285
+ * @param file File to create preview for
286
+ * @returns Preview URL or empty string
287
+ */
288
+ function createPreviewUrl(file: File): string {
289
+ if (isHeicFile(file)) return '';
290
+ if (file.type.startsWith('image/')) {
291
+ return URL.createObjectURL(file);
292
+ }
293
+ return '';
294
+ }
295
+
296
+ function isHeicFile(file: File): boolean {
297
+ const extension = '.' + file.name.split('.').pop()?.toLowerCase();
298
+ return file.type === 'image/heic' || file.type === 'image/heif' ||
299
+ extension === '.heic' || extension === '.heif';
300
+ }
301
+
302
+ /**
303
+ * Estimates the time remaining for an upload
304
+ * @param file File being uploaded
305
+ * @param progress Current progress (0-100)
306
+ * @param startTime Time when upload started
307
+ * @returns Formatted time remaining string
308
+ */
309
+ function estimateTimeRemaining(file: File, progress: number, startTime: number): string {
310
+ if (progress === 0) return '';
311
+
312
+ const elapsedMs = Date.now() - startTime;
313
+ const totalEstimatedMs = (elapsedMs / progress) * 100;
314
+ const remainingMs = totalEstimatedMs - elapsedMs;
315
+
316
+ if (remainingMs < 1000) return 'less than a second';
317
+ if (remainingMs < 60000) return `${Math.round(remainingMs / 1000)} seconds`;
318
+ return `${Math.round(remainingMs / 60000)} minutes`;
319
+ }
320
+
321
+ /**
322
+ * Handles cancellation of an upload
323
+ * @param id ID of upload to cancel
324
+ */
325
+ function handleCancelUpload(id: string) {
326
+ const uploadItem = uploadItems.find(item => item.id === id);
327
+ if (uploadItem) {
328
+ // Abort the upload if it's in progress
329
+ if (uploadItem.status === 'uploading' && uploadItem.controller) {
330
+ uploadItem.controller.abort();
331
+ }
332
+
333
+ // Remove the item from the list
334
+ uploadItems = uploadItems.filter(item => item.id !== id);
335
+
336
+ // Update uploading status if no more uploads are in progress
337
+ if (uploadItems.filter(item => item.status === 'uploading').length === 0) {
338
+ uploadInProgress = false;
339
+ }
340
+
341
+ if(showLogs) console.log(`Cancelled upload of ${uploadItem.file.name}`);
342
+ }
343
+ }
344
+
345
+ /**
346
+ * Handles retry of a failed upload
347
+ * @param id ID of upload to retry
348
+ */
349
+ function handleRetryUpload(id: string) {
350
+ const uploadItem = uploadItems.find(item => item.id === id);
351
+ if (uploadItem && uploadItem.status === 'failed') {
352
+ if(showLogs) console.log(`Retrying upload of ${uploadItem.file.name}`);
353
+
354
+ // Reset the upload item
355
+ const file = uploadItem.file;
356
+
357
+ // Remove the old item
358
+ uploadItems = uploadItems.filter(item => item.id !== id);
359
+
360
+ // Start a new upload for this file
361
+ uploadSingleFile(file);
362
+ }
363
+ }
364
+
365
+ /**
366
+ * Uploads a single file and tracks its progress
367
+ * @param file File to upload
368
+ */
369
+ async function uploadSingleFile(file: File) {
370
+ const normalizedFile = normalizeFileMimeType(file);
371
+ const fileExtension = '.' + normalizedFile.name.split('.').pop()?.toLowerCase();
372
+ if (!acceptTypes.includes(fileExtension)) {
373
+ console.error(`File type not allowed: ${normalizedFile.name}`);
374
+ dispatch('error', { message: `File type not allowed: ${normalizedFile.name}. Please use ${filter === 'document' ? 'document' : allowedTypesDisplayText} files only.` });
375
+ return;
376
+ }
377
+
378
+ if (restrictDuplicateNames && isDuplicate(normalizedFile.name, fileExtension)) {
379
+ if(showLogs) console.log(`Skipping duplicate file: ${normalizedFile.name}`);
380
+ return;
381
+ }
382
+
383
+ // Create a unique ID for this upload
384
+ const uploadId = `upload_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
385
+ const startTime = Date.now();
386
+ const previewUrl = createPreviewUrl(normalizedFile);
387
+ const controller = new AbortController();
388
+
389
+ // Create an upload item
390
+ const uploadItem: UploadItem = {
391
+ id: uploadId,
392
+ file: normalizedFile,
393
+ progress: 0,
394
+ status: 'uploading',
395
+ previewUrl,
396
+ controller,
397
+ timeRemaining: 'calculating...'
398
+ };
399
+
400
+ // Add to the list of uploads
401
+ uploadItems = [...uploadItems, uploadItem];
402
+ uploadInProgress = true;
403
+
404
+ try {
405
+ const path = currentPath.join('/');
406
+ const formData = new FormData();
407
+ formData.append('file', normalizedFile);
408
+ formData.append('path', path);
409
+ formData.append('folderId', currentFolderId);
410
+
411
+ const uploadConfig = get(fileBrowserUploadConfig);
412
+ let response: { success: boolean; file?: any; error?: string };
413
+
414
+ if (uploadConfig?.accessToken && uploadConfig?.apiBasePath) {
415
+ if (showLogs) {
416
+ console.log('[FileUploader] Widgetic upload:', file.name, uploadConfig.contextType);
417
+ }
418
+ response = await uploadToWidgeticApi(normalizedFile, uploadConfig, {
419
+ abortSignal: controller.signal,
420
+ onProgress: ({ percentage }) => {
421
+ const timeRemaining = estimateTimeRemaining(normalizedFile, percentage, startTime);
422
+ uploadItems = uploadItems.map((item) =>
423
+ item.id === uploadId
424
+ ? { ...item, progress: percentage, timeRemaining }
425
+ : item,
426
+ );
427
+ },
428
+ });
429
+ } else {
430
+ if (showLogs) {
431
+ console.log(`[FileUploader] Mock upload ${file.name} to path: ${path}, folder: ${currentFolderId}`);
432
+ }
433
+
434
+ const progressInterval = setInterval(() => {
435
+ const currentItem = uploadItems.find((item) => item.id === uploadId);
436
+ if (!currentItem || currentItem.status !== 'uploading') {
437
+ clearInterval(progressInterval);
438
+ return;
439
+ }
440
+ const newProgress = Math.min(95, currentItem.progress + Math.random() * 10);
441
+ const timeRemaining = estimateTimeRemaining(file, newProgress, startTime);
442
+ uploadItems = uploadItems.map((item) =>
443
+ item.id === uploadId ? { ...item, progress: newProgress, timeRemaining } : item,
444
+ );
445
+ }, 500);
446
+
447
+ const uploadTime = Math.random() * 3000 + 2000;
448
+ if (Math.random() < 0.2) {
449
+ clearInterval(progressInterval);
450
+ throw new Error('Network error');
451
+ }
452
+
453
+ await new Promise((resolve) => {
454
+ setTimeout(() => {
455
+ clearInterval(progressInterval);
456
+ resolve(null);
457
+ }, uploadTime);
458
+ });
459
+
460
+ response = await mockUploadAPI(formData);
461
+ }
462
+
463
+ if (response.success) {
464
+ const cdnUrl = response.file?.url;
465
+ // Swap blob preview for CDN URL after upload so preview pane is not stuck black
466
+ if (cdnUrl && previewUrl.startsWith('blob:')) {
467
+ URL.revokeObjectURL(previewUrl);
468
+ }
469
+ uploadItems = uploadItems.map(item =>
470
+ item.id === uploadId
471
+ ? {
472
+ ...item,
473
+ progress: 100,
474
+ status: 'complete',
475
+ timeRemaining: '',
476
+ previewUrl: cdnUrl || item.previewUrl,
477
+ }
478
+ : item
479
+ );
480
+ dispatch('fileUploaded', {
481
+ file: response.file,
482
+ path,
483
+ folderId: currentFolderId,
484
+ success: true
485
+ });
486
+
487
+ // Close progress overlay so the file grid is visible again (black dim was the upload overlay)
488
+ scheduleUploadDrawerDismiss();
489
+ } else {
490
+ // Update the upload item to failed
491
+ uploadItems = uploadItems.map(item =>
492
+ item.id === uploadId
493
+ ? {
494
+ ...item,
495
+ progress: 0,
496
+ status: 'failed',
497
+ errorMessage: response.error || 'Server error',
498
+ timeRemaining: ''
499
+ }
500
+ : item
501
+ );
502
+
503
+ dispatch('error', {
504
+ message: response.error || 'Server error',
505
+ file: file.name
506
+ });
507
+ }
508
+ } catch (error) {
509
+ console.error('Upload failed:', error);
510
+
511
+ // Update the upload item with error status
512
+ uploadItems = uploadItems.map(item =>
513
+ item.id === uploadItem.id
514
+ ? {
515
+ ...item,
516
+ status: 'failed',
517
+ progress: 0,
518
+ errorMessage: error instanceof Error ? error.message : 'Unknown error',
519
+ }
520
+ : item
521
+ );
522
+
523
+ dispatch('error', {
524
+ message: error instanceof Error ? error.message : 'Unknown error',
525
+ file: file.name
526
+ });
527
+ } finally {
528
+ // Check if all uploads are complete
529
+ const hasActiveUploads = uploadItems.some(item => item.status === 'uploading');
530
+ if (!hasActiveUploads) {
531
+ uploading = false;
532
+ }
533
+
534
+ if (fileInput) fileInput.value = '';
535
+ }
536
+ }
537
+
538
+ /**
539
+ * Handles the upload of multiple files
540
+ * @param files The files to upload
541
+ */
542
+ async function handleFiles(files: FileList) {
543
+ // open the uploads overlay with the drawer open
544
+ isUploadsModalOpen = true;
545
+ isUploadsDrawerCollapsed = false;
546
+
547
+ // set the uploading state to true
548
+ uploading = true;
549
+
550
+ // prepare an array to store the files that were skipped
551
+ let skippedFiles: string[] = [];
552
+
553
+ // try to upload the files
554
+ try {
555
+ // Process each file
556
+ for (const file of files) {
557
+ const fileExtension = '.' + file.name.split('.').pop()?.toLowerCase();
558
+ if (!acceptTypes.includes(fileExtension)) {
559
+ console.error(`File type not allowed: ${file.name}`);
560
+ dispatch('error', { message: `File type not allowed: ${file.name}. Please use ${filter === 'document' ? 'document' : allowedTypesDisplayText} files only.` });
561
+ continue;
562
+ }
563
+
564
+ if (restrictDuplicateNames && isDuplicate(file.name, fileExtension)) {
565
+ if(showLogs) console.log(`Skipping duplicate file: ${file.name}`);
566
+ skippedFiles.push(file.name);
567
+ continue;
568
+ }
569
+
570
+ // Start upload for this file
571
+ uploadSingleFile(file);
572
+ }
573
+
574
+ // Show a toast for skipped files if any
575
+ if (skippedFiles.length > 0) {
576
+ const message = skippedFiles.length === 1
577
+ ? `Skipped duplicate file: ${skippedFiles[0]}`
578
+ : `Skipped ${skippedFiles.length} duplicate files`;
579
+
580
+ showToast('warning', message);
581
+ }
582
+ } catch (error) {
583
+ console.error('Upload failed:', error);
584
+ dispatch('error', { message: error instanceof Error ? error.message : 'Upload failed' });
585
+ }
586
+ }
587
+
588
+ // Mock API function
589
+ async function mockUploadAPI(formData: FormData): Promise<{
590
+ success: boolean;
591
+ file?: any;
592
+ error?: string;
593
+ }> {
594
+ // Simulate network delay
595
+ await new Promise(resolve => setTimeout(resolve, 1000));
596
+
597
+ try {
598
+ const uploadedFile = formData.get('file') as File;
599
+ if (!uploadedFile) {
600
+ throw new Error('No file provided');
601
+ }
602
+
603
+ // Create an object URL for the file
604
+ const objectUrl = URL.createObjectURL(uploadedFile);
605
+
606
+ // Create thumbnail URL for images
607
+ let thumbnailUrl = '';
608
+ if (uploadedFile.type.startsWith('image/')) {
609
+ thumbnailUrl = objectUrl;
610
+ }
611
+
612
+ // Get the path from formData
613
+ const path = formData.get('path') as string;
614
+ const folderId = formData.get('folderId') as string;
615
+
616
+ // Mock success response with actual file data
617
+ return {
618
+ success: true,
619
+ file: {
620
+ id: `file_${Math.random().toString(36).substr(2, 9)}`,
621
+ name: uploadedFile.name,
622
+ type: 'file',
623
+ size: uploadedFile.size,
624
+ modified: new Date().toISOString(),
625
+ url: objectUrl,
626
+ thumbnail: thumbnailUrl || undefined,
627
+ objectUrl, // Store the object URL for cleanup
628
+ path,
629
+ folderId
630
+ }
631
+ };
632
+ } catch (error) {
633
+ console.error('Upload error:', error);
634
+ return {
635
+ success: false,
636
+ error: error instanceof Error ? error.message : 'Failed to process file'
637
+ };
638
+ }
639
+ }
640
+
641
+ function handleMouseEnter(event: MouseEvent) {
642
+ mouseX = event.clientX;
643
+ mouseY = event.clientY;
644
+ showHelp = true;
645
+ }
646
+
647
+ function handleMouseMove(event: MouseEvent) {
648
+ mouseX = event.clientX;
649
+ mouseY = event.clientY;
650
+ }
651
+
652
+ function handleMouseLeave() {
653
+ showHelp = false;
654
+ }
655
+
656
+ function formatAllowedTypesText(types: string[]): string {
657
+ if (!types.length || filter === 'all') return 'any';
658
+
659
+ // Check if we have only SVG files
660
+ const hasSvgOnly = types.every(type => {
661
+ const cleanType = type.replace('.', '').toLowerCase();
662
+ return cleanType === 'svg';
663
+ });
664
+
665
+ if (hasSvgOnly) return 'SVG';
666
+
667
+ // Check if we have only document files
668
+ const hasDocumentsOnly = types.every(type => {
669
+ const cleanType = type.replace('.', '').toLowerCase();
670
+ return ['pdf', 'doc', 'docx', 'txt', 'md', 'csv', 'xls', 'xlsx', 'json', 'xml', 'log'].includes(cleanType);
671
+ });
672
+
673
+ if (hasDocumentsOnly) return 'document';
674
+
675
+ // Map file extensions to their categories
676
+ const typeCategories = new Set(types.map(type => {
677
+ const cleanType = type.replace('.', '').toLowerCase();
678
+ if (['jpg', 'jpeg', 'png', 'gif', 'webp'].includes(cleanType)) return 'image';
679
+ if (cleanType === 'svg') return 'SVG';
680
+ if (['mp4', 'webm', 'mov'].includes(cleanType)) return 'video';
681
+ if (['mp3', 'wav', 'ogg'].includes(cleanType)) return 'audio';
682
+ if (['pdf', 'doc', 'docx', 'txt', 'md', 'csv', 'xls', 'xlsx', 'json', 'xml', 'log'].includes(cleanType)) return 'document';
683
+ if (['ttf', 'otf', 'woff', 'woff2'].includes(cleanType)) return 'font';
684
+ return cleanType;
685
+ }));
686
+
687
+ return Array.from(typeCategories).join(', ');
688
+ }
689
+
690
+ // Function to retry all failed uploads
691
+ function retryAllFailedUploads() {
692
+ const failedUploads = uploadItems.filter(item => item.status === 'failed');
693
+ failedUploads.forEach(item => handleRetryUpload(item.id));
694
+ }
695
+
696
+ /**
697
+ * Clears all completed uploads from the list
698
+ */
699
+ function clearCompletedUploads() {
700
+ if(showLogs) console.log('Clearing completed uploads');
701
+
702
+ // Remove all completed uploads from the list
703
+ uploadItems = uploadItems.filter(item => item.status !== 'complete');
704
+
705
+ // dispatch an event to notify that all uploads have been cleared
706
+ if (uploadItems.length === 0) { dispatch('uploadsCleared'); }
707
+ }
708
+
709
+ // Function to toggle drawer collapsed state
710
+ function toggleDrawerCollapse() {
711
+ isUploadsDrawerCollapsed = !isUploadsDrawerCollapsed;
712
+ // if(showLogs) console.log('Panel collapsed state:', isUploadsDrawerCollapsed);
713
+ }
714
+
715
+ // Handle window resize
716
+ function handleResize() {
717
+ if (browser) {
718
+ isSmallScreen = window.innerWidth <= 768;
719
+ }
720
+ }
721
+
722
+ function handleCollapseMouseEnter(event: MouseEvent) {
723
+ mouseX = event.clientX;
724
+ mouseY = event.clientY;
725
+ showCollapseTooltip = true;
726
+ }
727
+
728
+ function handleCollapseMouseLeave() {
729
+ showCollapseTooltip = false;
730
+ }
731
+
732
+ function handleCloseMouseEnter(event: MouseEvent) {
733
+ mouseX = event.clientX;
734
+ mouseY = event.clientY;
735
+ showCloseTooltip = true;
736
+ }
737
+
738
+ function handleCloseMouseLeave() {
739
+ showCloseTooltip = false;
740
+ }
741
+
742
+ // Function to handle manual close of the uploader
743
+ function handleManualClose() {
744
+ if(showLogs) console.log('Close button clicked, manually closing the uploader');
745
+ isUploadsModalOpen = false;
746
+ isUploadsDrawerCollapsed = true;
747
+ }
748
+
749
+ /** After uploads finish, close the dim overlay so the file grid is usable again. */
750
+ function scheduleUploadDrawerDismiss() {
751
+ const allDone = uploadItems.every(
752
+ (item) => item.status === 'complete' || item.status === 'failed',
753
+ );
754
+ if (!allDone) return;
755
+ setTimeout(() => {
756
+ const stillDone = uploadItems.every(
757
+ (item) => item.status === 'complete' || item.status === 'failed',
758
+ );
759
+ if (!stillDone) return;
760
+ isUploadsModalOpen = false;
761
+ isUploadsDrawerCollapsed = true;
762
+ uploadItems = uploadItems.filter((item) => item.status === 'failed');
763
+ if (uploadItems.length === 0) {
764
+ dispatch('uploadsCleared');
765
+ }
766
+ }, 600);
767
+ }
768
+
769
+ onMount(() => {
770
+ // if(showLogs) console.log('FileUploader mounted');
771
+
772
+ // Get parent element for portal
773
+ if (!portalTarget && uploaderRootEl && uploaderRootEl.parentElement) {
774
+ portalTarget = uploaderRootEl.parentElement;
775
+ if(showLogs) console.log('FileUploader parent element:', portalTarget);
776
+ }
777
+
778
+ // Set up resize listener
779
+ if (browser) {
780
+ window.addEventListener('resize', handleResize);
781
+ return () => {
782
+ window.removeEventListener('resize', handleResize);
783
+ };
784
+ }
785
+ });
786
+ </script>
787
+
788
+ <!-- svelte-ignore a11y_no_static_element_interactions -->
789
+ <div
790
+ class="file-uploader-component relative w-full flex-shrink-0 file-uploader widgetic-colors"
791
+ bind:this={uploaderRootEl}
792
+ >
793
+ <!-- Add help icon with tooltip -->
794
+ <div class="help-icon-container absolute {isSmallScreen ? 'top-2 right-2' : 'top-4 right-4'} z-10">
795
+ <Tooltip.Provider>
796
+ <Tooltip.Root open={showHelp}>
797
+ <Tooltip.Trigger class="focus:outline-none focus-visible:outline-none inline-block">
798
+ <div
799
+ class="flex items-center justify-center w-5 h-5 cursor-pointer transition-colors focus:outline-none focus-visible:outline-none"
800
+ onmouseenter={handleMouseEnter}
801
+ onmousemove={handleMouseMove}
802
+ onmouseleave={handleMouseLeave}
803
+ >
804
+ <IconHelp class="w-5 h-5 text-[hsl(var(--grey3))] hover:text-[hsl(var(--deep-forest-green))] transition-colors" />
805
+ </div>
806
+ </Tooltip.Trigger>
807
+ <Tooltip.Content
808
+ side="left"
809
+ sideOffset={5}
810
+ class="bg-[hsl(var(--dark))] text-white z-[99999] overflow-hidden rounded-md px-3 py-1.5 shadow-md max-w-[250px] whitespace-normal break-words"
811
+ style="position: fixed; left: {mouseX - 20}px; top: {mouseY}px;"
812
+ >
813
+ <p class="caption text-white whitespace-pre-line">{tooltipTypesText}</p>
814
+ </Tooltip.Content>
815
+ </Tooltip.Root>
816
+ </Tooltip.Provider>
817
+ </div>
818
+
819
+ <!-- Upload Area -->
820
+ <div
821
+ class="upload-area-ct relative w-full {isSmallScreen ? 'h-[56px]' : 'h-[112px]'} border-dashed rounded-large widgetic-radius transition-all duration-300 focus:outline-none focus-visible:outline-none border-[hsl(var(--forest-green))] [border-width:1px] {
822
+ dragActive
823
+ ? (dragInvalid
824
+ ? 'border-[hsl(var(--error))] bg-[hsl(var(--light-error))]'
825
+ : hasValidFiles
826
+ ? 'border-[hsl(var(--sage-green))] bg-[hsl(var(--light-green))]'
827
+ : 'border-[hsl(var(--forest-green))]')
828
+ : 'border-[hsl(var(--forest-green))]'
829
+ }"
830
+ style="border-radius: var(--radius-large); border-style: dashed; border-width: 1px;"
831
+ >
832
+ <input
833
+ type="file"
834
+ bind:this={fileInput}
835
+ onchange={handleFileSelect}
836
+ multiple
837
+ class="upload-input hidden"
838
+ accept={acceptTypes}
839
+ />
840
+
841
+ <div class="upload-zone w-full h-full inset-0 flex flex-col items-center justify-center p-4 space-y-2 text-center">
842
+ {#if uploading && uploadItems.length === 0}
843
+ <div class="caption text-[hsl(var(--grey3))]">Uploading...</div>
844
+ {:else if dragActive && dragInvalid}
845
+ {#if isDraggingFolder}
846
+ <div class="caption text-[hsl(var(--error))]">
847
+ Folders cannot be uploaded
848
+ </div>
849
+ {:else}
850
+ <div class="caption text-[hsl(var(--error))]">
851
+ Invalid file type. Please use {filter === 'document' ? 'document' : allowedTypesDisplayText} files only.
852
+ </div>
853
+ {/if}
854
+ {:else if dragActive && hasValidFiles}
855
+ <div class="caption text-[hsl(var(--sage-green))]">
856
+ Drop to upload {filter === 'document' ? 'document' : allowedTypesDisplayText} files
857
+ </div>
858
+ {:else if isSmallScreen}
859
+ <!-- Small screen version with clickable text -->
860
+ <button
861
+ class="caption text-[hsl(var(--grey3))] hover:text-[hsl(var(--deep-forest-green))] transition-colors"
862
+ onclick={() => fileInput.click()}
863
+ >
864
+ <span class="underline">Upload</span> or drop {filter === 'document' ? 'document' : allowedTypesDisplayText} files here
865
+ </button>
866
+ {:else}
867
+ <Button
868
+ variant="secondary"
869
+ class="btn-secondary rounded-small widgetic-radius focus:outline-none focus-visible:outline-none focus:ring-0 focus-visible:ring-0 hover:border-[hsl(var(--light-green))] transition-colors file-uploader-button"
870
+ onclick={() => fileInput.click()}
871
+ >
872
+ Upload {filter === 'document' ? 'document' : allowedTypesDisplayText} files
873
+ </Button>
874
+ <div class="caption text-[hsl(var(--grey3))]">
875
+ or drag and drop {filter === 'document' ? 'document' : allowedTypesDisplayText} files here
876
+ </div>
877
+ {/if}
878
+ </div>
879
+ </div>
880
+
881
+ <!-- Custom upload panel instead of Drawer -->
882
+ {#if isUploadsModalOpen && portalTarget}
883
+ <Portal target={portalTarget} class="uploads-modal widgetic-colors">
884
+ <!-- Simple overlay to prevent interaction when panel is open and not collapsed -->
885
+ {#if !isUploadsDrawerCollapsed}
886
+ <div
887
+ class="uploads-overlay-bg absolute inset-0 bg-black bg-opacity-50 z-[9980]"
888
+ onclick={() => {
889
+ isUploadsDrawerCollapsed = true;
890
+ if(showLogs) console.log('Overlay clicked, collapsing panel');
891
+ }}
892
+ aria-hidden="true"
893
+ ></div>
894
+ {/if}
895
+
896
+ <!-- Uploads Drawer -->
897
+ <div
898
+ class="uploads-drawer absolute bottom-0 left-0 right-0 bg-white transition-all duration-300 z-[9990] flex flex-col rounded-t-large widgetic-radius modal-shadow"
899
+ style="max-height: 80vh; transform: translateY({isUploadsDrawerCollapsed ? 'calc(100% - 70px)' : '0'}); border: 1px solid hsl(var(--forest-green)); border-bottom: none;"
900
+ >
901
+ <!-- Header with toggle -->
902
+ <div class="uploads-header flex flex-row items-center justify-between p-4">
903
+ <div class="uploads-header-content">
904
+ <h3 class="body-medium text-[hsl(var(--grey7))]">File Upload Progress</h3>
905
+ <p class="subtext text-[hsl(var(--grey5))]">
906
+ {uploadItems.filter(item => item.status === 'complete').length}/{uploadItems.length} files uploaded
907
+ {#if uploadItems.filter(item => item.status === 'failed').length > 0}
908
+ <span class="ml-2 caption text-[hsl(var(--error))]">
909
+ {uploadItems.filter(item => item.status === 'failed').length} failed
910
+ </span>
911
+ {/if}
912
+ </p>
913
+ </div>
914
+
915
+ <!-- Header Controls Container -->
916
+ <div class="uploads-header-controls">
917
+ <!-- Collapse/Expand button -->
918
+ <Tooltip.Provider>
919
+ <Tooltip.Root open={showCollapseTooltip}>
920
+ <Tooltip.Trigger class="focus:outline-none">
921
+ <button
922
+ class="collapse-button text-[hsl(var(--grey5))] hover:text-[hsl(var(--grey7))] p-2 rounded transition-colors"
923
+ onclick={toggleDrawerCollapse}
924
+ onmouseenter={handleCollapseMouseEnter}
925
+ onmousemove={handleMouseMove}
926
+ onmouseleave={handleCollapseMouseLeave}
927
+ aria-label={isUploadsDrawerCollapsed ? "Expand panel" : "Collapse panel"}
928
+ >
929
+ {#if isUploadsDrawerCollapsed}
930
+ <IconChevronUp class="h-5 w-5" />
931
+ {:else}
932
+ <IconChevronDown class="h-5 w-5" />
933
+ {/if}
934
+ </button>
935
+ </Tooltip.Trigger>
936
+ <Tooltip.Content
937
+ side="left"
938
+ sideOffset={5}
939
+ class="bg-[hsl(var(--dark))] text-white z-[99999] overflow-hidden rounded-md px-3 py-1.5 shadow-md"
940
+ style="position: fixed; left: {mouseX - 20}px; top: {mouseY}px;"
941
+ >
942
+ <p class="caption text-white">{isUploadsDrawerCollapsed ? "Expand uploader" : "Collapse uploader"}</p>
943
+ </Tooltip.Content>
944
+ </Tooltip.Root>
945
+ </Tooltip.Provider>
946
+
947
+ <!-- Close Button -->
948
+ <Tooltip.Provider>
949
+ <Tooltip.Root open={showCloseTooltip}>
950
+ <Tooltip.Trigger class="focus:outline-none">
951
+ <button
952
+ class="close-button text-[hsl(var(--grey5))] hover:text-[hsl(var(--grey7))] p-2 rounded transition-colors"
953
+ onclick={handleManualClose}
954
+ onmouseenter={handleCloseMouseEnter}
955
+ onmousemove={handleMouseMove}
956
+ onmouseleave={handleCloseMouseLeave}
957
+ aria-label="Close uploader"
958
+ >
959
+ <IconX class="h-5 w-5" />
960
+ </button>
961
+ </Tooltip.Trigger>
962
+ <Tooltip.Content
963
+ side="left"
964
+ sideOffset={5}
965
+ class="bg-[hsl(var(--dark))] text-white z-[99999] overflow-hidden rounded-md px-3 py-1.5 shadow-md"
966
+ style="position: fixed; left: {mouseX - 20}px; top: {mouseY}px;"
967
+ >
968
+ <p class="caption text-white">Close uploader</p>
969
+ </Tooltip.Content>
970
+ </Tooltip.Root>
971
+ </Tooltip.Provider>
972
+ </div>
973
+ </div>
974
+
975
+ <!-- Content (collapsible) -->
976
+ {#if uploadItems.length > 0}
977
+ <div
978
+ class="uploads-drawer-content transition-all duration-300 overflow-hidden flex-grow border-t border-[hsl(var(--forest-green))]"
979
+ style="max-height: {isUploadsDrawerCollapsed ? '0' : 'calc(60vh - 130px)'}; opacity: {isUploadsDrawerCollapsed ? '0' : '1'}; border-top-width: {isUploadsDrawerCollapsed ? '0' : '1px'};"
980
+ >
981
+ <div class="uplods-content-ct flex flex-col gap-4 p-4 overflow-y-auto" style="max-height: calc(60vh - 150px);">
982
+ <!-- Overall progress bar -->
983
+ <div class="uploads-overall-progress-bar w-full h-4 bg-[hsl(var(--light-green))] rounded-full overflow-hidden">
984
+ <div
985
+ class="progress-bar h-full bg-[hsl(var(--sage-green))]"
986
+ style="width: {overallProgress}%;"
987
+ ></div>
988
+ </div>
989
+
990
+ <!-- Upload items list -->
991
+ <div class="uploads-items-list space-y-4 overflow-y-auto">
992
+ {#each uploadItems as item (item.id)}
993
+ <div class="uploads-item rounded-large p-4 flex flex-col space-y-2 {item.status === 'failed' ? 'bg-[hsl(var(--light-error))] border border-[hsl(var(--error))]' : item.status === 'complete' ? 'bg-[hsl(var(--light-green))] border border-[hsl(var(--forest-green))]' : 'border border-[hsl(var(--forest-green))]'}"
994
+ >
995
+ <div class="flex items-center justify-between">
996
+ <div class="flex items-center gap-3 truncate">
997
+ {#if item.previewUrl}
998
+ <img src={item.previewUrl} alt="Preview" class="w-[62px] h-[54px] object-cover rounded-large" />
999
+ {:else}
1000
+ <div class="w-[62px] h-[54px] bg-[hsl(var(--grey1))] rounded-large flex items-center justify-center">
1001
+ <span class="text-xs">{item.file.name.split('.').pop()?.toUpperCase()}</span>
1002
+ </div>
1003
+ {/if}
1004
+ <div class="flex flex-col">
1005
+ <span class="body-medium truncate {item.status === 'failed' ? 'text-[hsl(var(--error))]' : 'text-[hsl(var(--grey7))]'}">{item.file.name}</span>
1006
+ <span class="subtext truncate text-[hsl(var(--grey5))]">{(item.file.size / 1024).toFixed(1)} KB</span>
1007
+ </div>
1008
+ </div>
1009
+
1010
+ {#if item.status === 'uploading'}
1011
+ <button
1012
+ class="text-[hsl(var(--grey5))] hover:text-[hsl(var(--grey7))] transition-colors"
1013
+ onclick={() => handleCancelUpload(item.id)}
1014
+ aria-label="Cancel upload"
1015
+ >
1016
+ <IconX class="h-4 w-4" />
1017
+ </button>
1018
+ {:else if item.status === 'failed'}
1019
+ <!-- Refresh button moved to error message section -->
1020
+ {:else}
1021
+ <div class="rounded-full w-5 h-5 bg-[hsl(var(--sage-green))] flex items-center justify-center">
1022
+ <img src={getAssetUrl('/icons/checked.svg')} alt="Completed" class="w-5 h-5" />
1023
+ </div>
1024
+ {/if}
1025
+ </div>
1026
+
1027
+ {#if item.status === 'uploading'}
1028
+ <div class="w-full">
1029
+ <div class="w-full h-1 bg-[hsl(var(--light-green))] rounded-full overflow-hidden">
1030
+ <div
1031
+ class="h-full bg-[hsl(var(--sage-green))]"
1032
+ style="width: {item.progress}%;"
1033
+ ></div>
1034
+ </div>
1035
+ <div class="flex justify-between mt-1">
1036
+ <span class="caption text-[hsl(var(--grey5))]">{Math.round(item.progress)}%</span>
1037
+ {#if item.timeRemaining}
1038
+ <span class="caption text-[hsl(var(--grey5))]">{item.timeRemaining}</span>
1039
+ {/if}
1040
+ </div>
1041
+ </div>
1042
+ {:else if item.status === 'failed'}
1043
+ <div class="flex items-center justify-between">
1044
+ <p class="caption text-[hsl(var(--error))]">
1045
+ Network error
1046
+ </p>
1047
+ <button
1048
+ class="text-[hsl(var(--grey5))] hover:text-[hsl(var(--grey7))] transition-colors flex items-center justify-center w-5 h-5"
1049
+ onclick={() => handleRetryUpload(item.id)}
1050
+ aria-label="Retry upload"
1051
+ >
1052
+ <IconRefresh class="h-5 w-5" />
1053
+ </button>
1054
+ </div>
1055
+ {/if}
1056
+ </div>
1057
+ {/each}
1058
+ </div>
1059
+ </div>
1060
+ </div>
1061
+
1062
+ <!-- Footer - Always visible even when content is collapsed -->
1063
+ <div class="uploads-drawer-footer p-4 border-t border-[hsl(var(--forest-green))] flex justify-between mt-auto sticky bottom-0 bg-white upload-panel-footer">
1064
+
1065
+ <!-- Retry failed uploads button -->
1066
+ {#if uploadItems.filter(item => item.status === 'failed').length > 0}
1067
+ <button
1068
+ class="retry-failed-uploads-btn body-medium text-[hsl(var(--grey5))] hover:text-[hsl(var(--grey7))] transition-colors underline"
1069
+ onclick={retryAllFailedUploads}
1070
+ >
1071
+ Retry failed uploads?
1072
+ </button>
1073
+ {/if}
1074
+
1075
+ <!-- Clear completed uploads button -->
1076
+ {#if uploadItems.filter(item => item.status === 'complete').length > 0}
1077
+ <button
1078
+ class="clear-completed-uploads-btn btn-secondary h-8 px-3 text-[hsl(var(--grey5))] hover:text-[hsl(var(--grey7))] transition-colors rounded-small"
1079
+ onclick={clearCompletedUploads}
1080
+ >
1081
+ Clear completed uploads
1082
+ </button>
1083
+ {/if}
1084
+
1085
+ </div>
1086
+
1087
+ {/if}
1088
+
1089
+ </div>
1090
+ </Portal>
1091
+ {/if}
1092
+
1093
+ </div>
1094
+
1095
+ <style>
1096
+ :global(.file-uploader button) {
1097
+ outline: none !important;
1098
+ box-shadow: none !important;
1099
+ --tw-ring-offset-width: 0 !important;
1100
+ --tw-ring-width: 0 !important;
1101
+ }
1102
+
1103
+ :global(.file-uploader button:focus),
1104
+ :global(.file-uploader button:focus-visible) {
1105
+ outline: none !important;
1106
+ box-shadow: none !important;
1107
+ --tw-ring-offset-width: 0 !important;
1108
+ --tw-ring-width: 0 !important;
1109
+ }
1110
+
1111
+ /* Override button text to use subtext style */
1112
+ :global(.file-uploader-button) {
1113
+ font-family: 'Riegla Regular' !important;
1114
+ font-size: 16px !important;
1115
+ line-height: 1.4 !important;
1116
+ font-weight: 400 !important;
1117
+ }
1118
+
1119
+ /* Override button text to ensure it's not bold */
1120
+ :global(.file-uploader-button span) {
1121
+ font-weight: 400 !important;
1122
+ font-family: 'Riegla Regular' !important;
1123
+ }
1124
+
1125
+ /* Make sure drawer appears on top of other elements */
1126
+ :global(.drawer-content) {
1127
+ z-index: 9999 !important;
1128
+ }
1129
+
1130
+ /* Ensure the drawer content is visible */
1131
+ :global(.drawer) {
1132
+ position: relative;
1133
+ z-index: 9999 !important;
1134
+ }
1135
+
1136
+ /* Upload panel styles */
1137
+ :global(.upload-panel) {
1138
+ box-shadow: 0px 2px 10px 0px rgba(0, 0, 0, 0.1);
1139
+ display: flex;
1140
+ flex-direction: column;
1141
+ border-top-left-radius: var(--radius-large);
1142
+ border-top-right-radius: var(--radius-large);
1143
+ }
1144
+
1145
+ /* Fix footer position */
1146
+ :global(.upload-panel-footer) {
1147
+ position: sticky;
1148
+ bottom: 0;
1149
+ background-color: white;
1150
+ z-index: 10;
1151
+ }
1152
+ </style>