@widgetic/file-browser 0.5.37 → 0.5.38

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 (44) hide show
  1. package/dist/components/FolderTree.svelte.d.ts +2 -6
  2. package/dist/components/core/FileBrowser.svelte +85 -96
  3. package/dist/components/core/FileUploader.svelte +307 -133
  4. package/dist/components/core/RecentFiles.svelte +21 -8
  5. package/dist/components/core/SearchDropdown.svelte +312 -0
  6. package/dist/components/core/SearchDropdown.svelte.d.ts +30 -0
  7. package/dist/components/core/UploadPanel.svelte +27 -15
  8. package/dist/components/core/UploadPanel.svelte.d.ts +3 -0
  9. package/dist/components/core/UploadRow.svelte +22 -1
  10. package/dist/components/core/UploadRow.svelte.d.ts +3 -0
  11. package/dist/components/core/index.d.ts +1 -0
  12. package/dist/components/core/index.js +1 -0
  13. package/dist/components/items/FileItem.svelte +28 -3
  14. package/dist/components/items/FolderItem.svelte +21 -2
  15. package/dist/components/modals/MoveDialog.svelte +16 -11
  16. package/dist/components/modals/MoveDialog.svelte.d.ts +1 -0
  17. package/dist/components/modals/SearchModal.svelte +4 -44
  18. package/dist/components/ui/DropdownMenu.svelte +7 -3
  19. package/dist/components/ui/DropdownMenu.svelte.d.ts +1 -0
  20. package/dist/i18n/messages.d.ts +7 -1
  21. package/dist/i18n/messages.js +7 -1
  22. package/dist/stores/fileStore.d.ts +2 -2
  23. package/dist/stores/navigationStore.d.ts +1 -1
  24. package/dist/stores/persistentSelectStore.d.ts +1 -1
  25. package/dist/utils/fileNames.d.ts +9 -0
  26. package/dist/utils/fileNames.js +19 -0
  27. package/dist/utils/libraryTree.d.ts +22 -0
  28. package/dist/utils/libraryTree.js +177 -0
  29. package/dist/utils/searchItems.d.ts +27 -0
  30. package/dist/utils/searchItems.js +77 -0
  31. package/dist/utils/uploadProgressMath.d.ts +29 -0
  32. package/dist/utils/uploadProgressMath.js +66 -0
  33. package/dist/utils/uploadResponseMapping.d.ts +11 -0
  34. package/dist/utils/uploadResponseMapping.js +51 -0
  35. package/dist/utils/uploadUiHelpers.d.ts +28 -0
  36. package/dist/utils/uploadUiHelpers.js +49 -0
  37. package/dist/utils/userUploadsStorage.d.ts +2 -2
  38. package/dist/utils/userUploadsStorage.js +25 -17
  39. package/dist/utils/widgeticTusUpload.d.ts +2 -0
  40. package/dist/utils/widgeticTusUpload.js +4 -20
  41. package/dist/utils/widgeticUpload.js +3 -66
  42. package/dist/utils/xhrMultipartUpload.d.ts +16 -0
  43. package/dist/utils/xhrMultipartUpload.js +125 -0
  44. package/package.json +3 -3
@@ -17,14 +17,10 @@ interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> =
17
17
  z_$$bindings?: Bindings;
18
18
  }
19
19
  declare const FolderTree: $$__sveltets_2_IsomorphicComponent<{
20
- folder: FileSystemItem & {
21
- displayChildren?: FileSystemItem[];
22
- };
20
+ folder: any;
23
21
  selectedFolder: FileSystemItem | undefined;
24
22
  immediateParentId: string | null;
25
- onSelect: (folder: FileSystemItem & {
26
- displayChildren?: FileSystemItem[];
27
- }) => void;
23
+ onSelect: (folder: any) => void;
28
24
  /** Kept for callers; rows use FileIcon instead of dynamic folder artwork. */ getFolderIconForItem: (folder: FileSystemItem) => string;
29
25
  customClasses?: string;
30
26
  iconSize?: string;
@@ -21,7 +21,7 @@
21
21
  import '@widgetic/design-system/styles';
22
22
 
23
23
  // Design system components
24
- import { Alert, Button, DebugGrid, WScrollArea, EmptyState, ErrorState, ActionModal, SearchInput, DropdownMenu, Tooltip, IconButton } from '@widgetic/design-system/components';
24
+ import { Alert, Button, DebugGrid, WScrollArea, EmptyState, ErrorState, ActionModal, DropdownMenu, Tooltip, IconButton } from '@widgetic/design-system/components';
25
25
  import {
26
26
  IconCheck,
27
27
  IconPhoto,
@@ -42,9 +42,9 @@
42
42
 
43
43
  // LOCAL COMPONENT IMPORTS
44
44
  import { NewFolderButton } from '../modals';
45
- import { RecentFiles, Header, FileUploader } from './';
45
+ import { RecentFiles, Header, FileUploader, SearchDropdown } from './';
46
46
  import { FilePreview } from '../previews';
47
- import { SelectedFilesModal, SearchModal, RenameDialog, MoveDialog } from '../modals';
47
+ import { SelectedFilesModal, RenameDialog, MoveDialog } from '../modals';
48
48
  import { NewItemDialog } from '@widgetic/design-system/components';
49
49
  import { FileItem, FolderItem } from '../items';
50
50
  import { VirtualList, DragSelect, ControlToolbar } from '../ui';
@@ -117,7 +117,7 @@
117
117
  import { resolveMediaLibrary, type ResolvedMediaLibrary } from '../../mediaLibrary/resolve';
118
118
  import { appendNewFiles, createLibraryRoot, removeFiles, replaceFile, upsertFile } from '../../mediaLibrary/treeOps';
119
119
  import type { MediaLibraryErrorCode, MediaLibraryProvider } from '../../mediaLibrary/types';
120
- import { getRenamedFileName } from '../../utils/fileNames';
120
+ import { getRenamedFileName, splitFileName } from '../../utils/fileNames';
121
121
 
122
122
  // I18N IMPORTS (the words of the File Browser, in the page's language)
123
123
  import { provideI18n } from '../../i18n/context';
@@ -443,7 +443,6 @@
443
443
 
444
444
  // Modal visibility states
445
445
  let showModal = false; // Selected files modal
446
- let showSearchModal = false; // Search interface
447
446
  let showRenameDialog = false; // Rename dialog
448
447
  let showMoveDialog = false; // Move file/folder dialog
449
448
  let showDeleteConfirmation = false; // Delete confirmation
@@ -453,6 +452,13 @@
453
452
  // It is set when the dialog opens, so the dialog names (and deletes) exactly what the visitor pointed at.
454
453
  let itemsPendingDeletion: FileSystemItem[] = [];
455
454
 
455
+ // The rename dialog edits the name of a file without its extension: the extension is always kept (see handleRename).
456
+ $: renameDialogDisplayName = selectedItem
457
+ ? selectedItem.type === 'file'
458
+ ? splitFileName(selectedItem.name).baseName
459
+ : selectedItem.name
460
+ : '';
461
+
456
462
  // UI state calculations
457
463
  // let controlsVisible: boolean;
458
464
  // $: controlsVisible = showFilters || showSorting;
@@ -471,6 +477,10 @@
471
477
  // A library supplies every file, so `data` handed in by the host is not used next to it.
472
478
  if (libraryMode) data = null;
473
479
 
480
+ // When the host draws the breadcrumbs in its own bar (`showBreadcrumbs` false) the first row of the browser has no
481
+ // header above it: it gets the top spacing of the header (Figma "Files" page, node 292:1945) so it is not cut off.
482
+ $: controlsTopPaddingClass = !showBreadcrumbs && !libraryMode ? (isCompactLayout ? 'pt-4' : 'pt-6') : '';
483
+
474
484
  // The library as the File Browser uses it: every answer checked, every failure a MediaLibraryError.
475
485
  let resolvedMediaLibrary: ResolvedMediaLibrary | null = null;
476
486
  // Set when `mediaLibrary` is not a usable library: the screen says so instead of showing files.
@@ -930,22 +940,6 @@
930
940
  * These functions handle user interactions with search and folder navigation
931
941
  */
932
942
 
933
- /**
934
- * Opens the search modal for file/folder search
935
- */
936
- function handleSearch() {
937
- if (!showModal) { // Don't show if selected files modal is open
938
- showSearchModal = true;
939
- }
940
- }
941
-
942
- /**
943
- * Closes the search modal and resets search state
944
- */
945
- function handleSearchClose() {
946
- showSearchModal = false;
947
- }
948
-
949
943
  /**
950
944
  * Handles navigation from search results
951
945
  * Processes the path and updates current location
@@ -976,7 +970,6 @@
976
970
  navigationStore.navigateToFolder(newPath, true);
977
971
  currentFolder.set(newPath);
978
972
  currentPath = newPath;
979
- showSearchModal = false;
980
973
 
981
974
  // If there's a preview item, handle it the same way for both search and selected files
982
975
  if (event.detail.preview) {
@@ -1408,9 +1401,7 @@
1408
1401
  $: selectedFilesCount = $selectedFiles.length;
1409
1402
 
1410
1403
  function toggleModal() {
1411
- if (!showSearchModal) { // Don't show if search modal is open
1412
- showModal = !showModal;
1413
- }
1404
+ showModal = !showModal;
1414
1405
  }
1415
1406
 
1416
1407
  /**
@@ -1423,6 +1414,16 @@
1423
1414
  const { action, item } = event.detail;
1424
1415
 
1425
1416
  if (isFileSystemItem(item)) {
1417
+ // The built-in Uploads folder always stays at the root (the library is rebuilt around it on every load)
1418
+ if (
1419
+ item.id === 'folder_my_uploads' &&
1420
+ item.type === 'folder' &&
1421
+ (action === 'rename' || action === 'move' || action === 'delete')
1422
+ ) {
1423
+ if (showLogs) console.log('[FileBrowser] Blocked action on built-in Uploads folder:', action);
1424
+ return;
1425
+ }
1426
+
1426
1427
  // Use allSelectedFiles instead of validSelectedFiles to get ALL selected files across ALL folders
1427
1428
  const validSelectedFiles = allSelectedFiles;
1428
1429
  // console.log('Current valid selections across all folders:', validSelectedFiles);
@@ -1523,6 +1524,8 @@
1523
1524
  // Store the item's ID before resetting selection
1524
1525
  const itemId = selectedItem.id;
1525
1526
  const oldName = selectedItem.name;
1527
+ // The name the item ends up with: the dialog edits a file without its extension, which is always kept
1528
+ const finalName = selectedItem.type === 'file' ? getRenamedFileName(selectedItem.name, newName.trim()) : newName.trim();
1526
1529
 
1527
1530
  // Close the dialog and reset selection immediately to prevent UI blocking
1528
1531
  showRenameDialog = false;
@@ -1542,8 +1545,10 @@
1542
1545
  // The File Browser was closed while the library was working: there is no one to tell.
1543
1546
  if (libraryMode && libraryActionsController.signal.aborted) return;
1544
1547
  if (success) {
1548
+ // The new name is part of the saved tree of the Widgetic library
1549
+ persistMyUploadsTree();
1545
1550
  showToast('success', $t('toast.rename.done'), {
1546
- description: $t('toast.rename.doneDetail', { oldName, newName }),
1551
+ description: $t('toast.rename.doneDetail', { oldName, newName: finalName }),
1547
1552
  });
1548
1553
  } else {
1549
1554
  showToast('error', $t('toast.rename.failed'), {
@@ -1715,11 +1720,14 @@
1715
1720
  }
1716
1721
  $: if (!libraryMode) nameBuiltInFolder($t('library.defaultLabel'));
1717
1722
 
1723
+ // Saves the whole root of the Widgetic library (the built-in Uploads folder, the folders next to it and the files loose
1724
+ // at the root), so an upload, a new folder, a rename or a move keeps its place after a reload.
1718
1725
  function persistMyUploadsTree() {
1726
+ // A host's media library (and the demo content) keep nothing on this device
1727
+ if (libraryMode || !isWidgeticLibraryMode()) return;
1719
1728
  const store = get(fileStore);
1720
- const myUploads = store.root?.children?.find((c) => c.id === 'folder_my_uploads');
1721
- if (myUploads?.children) {
1722
- saveLibraryTreeChildren(myUploads.children);
1729
+ if (store.root?.children) {
1730
+ saveLibraryTreeChildren(store.root.children);
1723
1731
  }
1724
1732
  }
1725
1733
 
@@ -1918,20 +1926,21 @@
1918
1926
 
1919
1927
  $: fileTypesText = formatFileTypesForDisplay($t);
1920
1928
 
1929
+ /** First segment of inline search location lines (header root / library label). */
1930
+ $: searchRootLabel = libraryMode
1931
+ ? (resolvedMediaLibrary?.hasOwnLabel ? resolvedMediaLibrary.label : $t('library.defaultLabel'))
1932
+ : $t('breadcrumbs.root');
1933
+
1921
1934
  function handleModalClose() {
1922
1935
  showModal = false;
1923
1936
  }
1924
1937
 
1925
- function handleSearchModalClose() {
1926
- showSearchModal = false;
1927
- }
1928
-
1929
1938
  /**
1930
1939
  * Handles successful file upload
1931
1940
  * Updates file list and sorts according to current criteria
1932
1941
  */
1933
1942
  function handleFileUploaded(event: CustomEvent) {
1934
- const { file, success } = event.detail;
1943
+ const { file, success, pathIds } = event.detail;
1935
1944
 
1936
1945
  // A media library keeps the file itself: the list only shows what it stored. Nothing is saved on this device.
1937
1946
  if (libraryMode) {
@@ -1949,35 +1958,38 @@
1949
1958
  };
1950
1959
  saveUserUpload(uploadedFile);
1951
1960
 
1961
+ // The folder the upload was started in: the visitor may have opened another folder while it was uploading
1962
+ const uploadPath: string[] = Array.isArray(pathIds) ? pathIds : currentPath;
1963
+ const isUploadFolderOpen =
1964
+ uploadPath.length === currentPath.length && uploadPath.every((id, index) => id === currentPath[index]);
1965
+
1952
1966
  // Update the fileStore with the new file
1953
1967
  fileStore.update(store => {
1954
1968
  if (!store.root) return store;
1955
1969
 
1956
- // Find the target folder in the store
1970
+ // Find the target folder in the store: an upload stays in the folder it was made in (the root too)
1957
1971
  let currentFolder = store.root;
1958
1972
 
1959
- if (isWidgeticLibraryMode()) {
1960
- const myUploads = store.root.children?.find(
1961
- (item) => item.type === 'folder' && item.id === 'folder_my_uploads',
1973
+ // Traverse to the target folder using the path of the upload
1974
+ for (const pathSegment of uploadPath) {
1975
+ const nextFolder = currentFolder.children?.find(
1976
+ item => item.type === 'folder' && item.id === pathSegment
1962
1977
  );
1963
- if (!myUploads) return store;
1964
- currentFolder = myUploads;
1965
- } else {
1966
- // Traverse to the target folder using currentPath
1967
- for (const pathSegment of currentPath) {
1968
- const nextFolder = currentFolder.children?.find(
1969
- item => item.type === 'folder' && item.id === pathSegment
1970
- );
1971
- if (!nextFolder) return store; // Path not found, return unchanged store
1972
- currentFolder = nextFolder;
1978
+ if (!nextFolder) {
1979
+ // The folder is gone (deleted or moved meanwhile): the root keeps the file instead of losing it
1980
+ currentFolder = store.root;
1981
+ break;
1973
1982
  }
1983
+ currentFolder = nextFolder;
1974
1984
  }
1975
1985
 
1976
1986
  // Add the new file to the current folder's children
1977
1987
  if (currentFolder.children) {
1978
- // Check for duplicates before adding
1988
+ // Check for duplicates before adding (the Widgetic library may hold two files with one name: compare ids)
1979
1989
  const isDuplicate = currentFolder.children.some(
1980
- existingFile => existingFile.name === file.name
1990
+ existingFile => isWidgeticLibraryMode()
1991
+ ? existingFile.id === uploadedFile.id
1992
+ : existingFile.name === file.name
1981
1993
  );
1982
1994
 
1983
1995
  if (!isDuplicate) {
@@ -2008,8 +2020,8 @@
2008
2020
  }
2009
2021
  });
2010
2022
 
2011
- // Force a reactive update of the current folder content
2012
- currentFolderContent = { ...currentFolder };
2023
+ // Force a reactive update of the current folder content (only when the upload folder is the one on screen)
2024
+ if (isUploadFolderOpen) currentFolderContent = { ...currentFolder };
2013
2025
 
2014
2026
  // Update recent files if we're in the root folder
2015
2027
  if (currentPath.length === 0) {
@@ -2017,7 +2029,7 @@
2017
2029
  }
2018
2030
 
2019
2031
  // Ensure the file appears in the virtual list by forcing an update
2020
- sortedFilteredFiles = [...sortedFilteredFiles, uploadedFile].sort((a, b) => {
2032
+ if (isUploadFolderOpen) sortedFilteredFiles = [...sortedFilteredFiles, uploadedFile].sort((a, b) => {
2021
2033
  if (a.type === 'folder' && b.type !== 'folder') return -1;
2022
2034
  if (a.type !== 'folder' && b.type === 'folder') return 1;
2023
2035
  return 0;
@@ -2026,12 +2038,12 @@
2026
2038
  // Log the file addition
2027
2039
  if(showLogs) console.log('Added file:', {
2028
2040
  name: file.name,
2029
- path: currentPath,
2041
+ path: uploadPath,
2030
2042
  url: file.url
2031
2043
  });
2032
2044
 
2033
2045
  // Scroll to and highlight the new file after a short delay to ensure rendering
2034
- setTimeout(() => {
2046
+ if (isUploadFolderOpen) setTimeout(() => {
2035
2047
  scrollItemIntoView(file.id);
2036
2048
  const itemElement = findItemElement(file.id);
2037
2049
  if (itemElement) {
@@ -2048,20 +2060,17 @@
2048
2060
  // Initialize children array if it doesn't exist
2049
2061
  currentFolder.children = [uploadedFile];
2050
2062
  // Force a reactive update
2051
- currentFolderContent = { ...currentFolder };
2052
- sortedFilteredFiles = [uploadedFile];
2063
+ if (isUploadFolderOpen) {
2064
+ currentFolderContent = { ...currentFolder };
2065
+ sortedFilteredFiles = [uploadedFile];
2066
+ }
2053
2067
  if(showLogs) console.log('Created new children array with file:', file.name);
2054
2068
  }
2055
2069
 
2056
2070
  return store;
2057
2071
  });
2072
+ // The file keeps its place in the saved tree of the Widgetic library (no jump to another folder after an upload)
2058
2073
  persistMyUploadsTree();
2059
- if (isWidgeticLibraryMode() && currentPath[0] !== 'folder_my_uploads') {
2060
- const myUploadsPath = ['folder_my_uploads'];
2061
- navigationStore.navigateToFolder(myUploadsPath, true);
2062
- currentFolder.set(myUploadsPath);
2063
- if (showLogs) console.log('[FileBrowser] Navigated into My uploads after upload');
2064
- }
2065
2074
  }
2066
2075
  }
2067
2076
 
@@ -2819,20 +2828,15 @@ mainGridClass="app-main-grid"
2819
2828
 
2820
2829
  <!-- FILE BROWSER CONTROLS (Search Field + filter/sort triggers) -->
2821
2830
  <!-- One row at every width: the search shrinks beside the filter and sort. With no header, this row carries the top inset. -->
2822
- <div class="file-browser-controls flex min-w-0 shrink-0 flex-nowrap items-center gap-2 pb-4 {edgePaddingClass} {!showHeader ? 'pt-6' : ''}">
2823
- <div class="search-bar-container flex min-w-0 flex-1 items-center">
2824
- <!-- svelte-ignore a11y_click_events_have_key_events -->
2825
- <div onclick={handleSearch} class="w-full cursor-pointer">
2826
- <SearchInput
2827
- placeholder={$t('search.placeholder')}
2828
- value=""
2829
- containerClass="w-full"
2830
- onInput={() => {}}
2831
- onKeydown={() => {}}
2832
- onClear={() => {}}
2833
- onPaste={() => {}}
2834
- />
2835
- </div>
2831
+ <div class="file-browser-controls flex min-w-0 shrink-0 flex-nowrap items-center gap-2 pb-4 {controlsTopPaddingClass} {edgePaddingClass}">
2832
+ <div class="search-bar-container relative z-[61] flex min-w-0 flex-1 items-center">
2833
+ <SearchDropdown
2834
+ root={$fileStore.root}
2835
+ currentFilter={filter}
2836
+ rootDisplayLabel={searchRootLabel}
2837
+ {showLogs}
2838
+ on:navigate={handleSearchNavigate}
2839
+ />
2836
2840
  </div>
2837
2841
 
2838
2842
  {#if showFilters || showSorting}
@@ -3200,17 +3204,6 @@ mainGridClass="app-main-grid"
3200
3204
  />
3201
3205
  {/if}
3202
3206
 
3203
- {#if showSearchModal}
3204
- <SearchModal
3205
- bind:open={showSearchModal}
3206
- target={rootContainerClass}
3207
- currentFilter={filter}
3208
- on:close={handleSearchModalClose}
3209
- on:navigate={handleSearchNavigate}
3210
- on:preview={(event : any) => handleFileClick(event.detail)}
3211
- />
3212
- {/if}
3213
-
3214
3207
  {#if previewFile}
3215
3208
  <FilePreview
3216
3209
  file={previewFile}
@@ -3227,7 +3220,7 @@ mainGridClass="app-main-grid"
3227
3220
  {#if showRenameDialog}
3228
3221
  <RenameDialog
3229
3222
  isOpen={showRenameDialog}
3230
- itemName={selectedItem?.name ?? ''}
3223
+ itemName={renameDialogDisplayName}
3231
3224
  itemType={selectedItem?.type === 'folder' ? 'folder' : 'file'}
3232
3225
  itemId={selectedItem?.id ?? ''}
3233
3226
  title={$t('dialog.rename.title')}
@@ -3260,6 +3253,8 @@ mainGridClass="app-main-grid"
3260
3253
  {sourceItems}
3261
3254
  currentPath={currentPath}
3262
3255
  target={rootContainerClass}
3256
+ localOnly={isWidgeticLibraryMode()}
3257
+ on:move={() => persistMyUploadsTree()}
3263
3258
  on:resetNavigation={handleResetNavigation}
3264
3259
  on:navigate={({ detail }: CustomEvent<NavigateEventDetail>) => {
3265
3260
  const newPath = Array.isArray(detail.targetFolderId)
@@ -3394,11 +3389,5 @@ mainGridClass="app-main-grid"
3394
3389
  transition: color 300ms ease, background-color 300ms ease, border-color 300ms ease !important;
3395
3390
  }
3396
3391
 
3397
- /* Add styles for the SearchInput component to make it read-only and clickable */
3398
- :global(.search-bar-container .w-full input) {
3399
- cursor: pointer !important;
3400
- pointer-events: all !important;
3401
- user-select: none !important;
3402
- }
3403
3392
  </style>
3404
- </div>
3393
+ </div>