Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Add browser extension UI scaffolding for subfolders (#1695)
Leendert de Borstcc71917f5e82
diff --git a/apps/browser-extension/src/entrypoints/popup/components/Folders/FolderBreadcrumb.tsx b/apps/browser-extension/src/entrypoints/popup/components/Folders/FolderBreadcrumb.tsxnew file mode 100644index 000000000..3e96d4f1b--- /dev/null+++ b/apps/browser-extension/src/entrypoints/popup/components/Folders/FolderBreadcrumb.tsx@@ -0,0 +1,106 @@+import React, { useMemo } from 'react';+import { useTranslation } from 'react-i18next';+import { useNavigate } from 'react-router-dom';++import { useDb } from '@/entrypoints/popup/context/DbContext';++import { getFolderPath, getFolderIdPath } from '@/utils/folderUtils';++type Breadcrumb = {+ name: string;+ id: string;+};++type FolderBreadcrumbProps = {+ /**+ * The ID of the current folder to show breadcrumbs for.+ * If null/undefined, no breadcrumbs are shown.+ */+ folderId: string | null | undefined;+ /**+ * Optional refresh key to force re-computation of breadcrumbs+ * (e.g., when folder is renamed).+ */+ refreshKey?: number;+ /**+ * Optional root path to navigate to when clicking the root breadcrumb.+ * Defaults to '/items'.+ */+ rootPath?: string;+ /**+ * Optional root label for the first breadcrumb.+ * Defaults to 'items.title' translation key.+ */+ rootLabel?: string;+};++/**+ * Displays a breadcrumb navigation trail for folder hierarchy.+ * Shows "Root > Parent Folder > Current Folder" with clickable links.+ */+const FolderBreadcrumb: React.FC<FolderBreadcrumbProps> = ({+ folderId,+ refreshKey = 0,+ rootPath = '/items',+ rootLabel,+}) => {+ const { t } = useTranslation();+ const navigate = useNavigate();+ const dbContext = useDb();++ /**+ * Compute breadcrumb trail based on current folder.+ */+ const breadcrumbs = useMemo((): Breadcrumb[] => {+ if (!folderId || !dbContext?.sqliteClient) {+ return [];+ }+ const allFolders = dbContext.sqliteClient.folders.getAll();+ const folderNames = getFolderPath(folderId, allFolders);+ const folderIds = getFolderIdPath(folderId, allFolders);+ return folderNames.map((name, index) => ({+ name,+ id: folderIds[index]+ }));+ }, [folderId, dbContext?.sqliteClient]);++ // Don't render anything if no breadcrumbs+ if (breadcrumbs.length === 0) {+ return null;+ }++ const rootLabelText = rootLabel ?? t('items.title');++ return (+ <div className="mb-3 flex items-center gap-1 text-sm text-gray-600 dark:text-gray-400 overflow-x-auto">+ <button+ onClick={() => navigate(rootPath)}+ className="hover:text-orange-600 dark:hover:text-orange-400 transition-colors flex-shrink-0"+ >+ {rootLabelText}+ </button>+ {breadcrumbs.map((crumb, index) => (+ <React.Fragment key={crumb.id}>+ <svg className="w-4 h-4 flex-shrink-0" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">+ <polyline points="9 6 15 12 9 18" />+ </svg>+ {index < breadcrumbs.length - 1 ? (+ <button+ onClick={() => navigate(`/items/folder/${crumb.id}`)}+ className="hover:text-orange-600 dark:hover:text-orange-400 transition-colors truncate"+ title={crumb.name}+ >+ {crumb.name}+ </button>+ ) : (+ <span className="text-gray-900 dark:text-white font-medium truncate" title={crumb.name}>+ {crumb.name}+ </span>+ )}+ </React.Fragment>+ ))}+ </div>+ );+};++export default FolderBreadcrumb;diff --git a/apps/browser-extension/src/entrypoints/popup/components/Items/ItemCard.tsx b/apps/browser-extension/src/entrypoints/popup/components/Items/ItemCard.tsxindex 691cb4822..66beb5422 100644--- a/apps/browser-extension/src/entrypoints/popup/components/Items/ItemCard.tsx+++ b/apps/browser-extension/src/entrypoints/popup/components/Items/ItemCard.tsx@@ -4,6 +4,7 @@ import { useNavigate } from 'react-router-dom';import type { Item } from '@/utils/dist/core/models/vault';import { FieldKey } from '@/utils/dist/core/models/vault';+import { truncateFolderPath } from '@/utils/folderUtils';import ItemIcon from './ItemIcon';@@ -64,6 +65,18 @@ const ItemCard: React.FC<ItemCardProps> = ({ item, showFolderPath = false, searcreturn returnValue.length > 33 ? returnValue.slice(0, 30) + '...' : returnValue;};+ /**+ * Get formatted folder path for display, truncating if needed.+ */+ const getFormattedFolderPath = (folderPath: string): string => {+ if (!folderPath) {+ return '';+ }+ const segments = folderPath.split(' > ');+ const truncated = truncateFolderPath(segments, 3);+ return truncated.join(' > ');+ };+return (<li><button@@ -82,7 +95,9 @@ const ItemCard: React.FC<ItemCardProps> = ({ item, showFolderPath = false, searc<p className="font-medium text-gray-900 dark:text-white">{showFolderPath && item.FolderPath ? (<>- <span className="text-gray-500 dark:text-gray-400 text-sm">{item.FolderPath} > </span>+ <span className="text-gray-500 dark:text-gray-400 text-sm" title={item.FolderPath}>+ {getFormattedFolderPath(item.FolderPath)} >{' '}+ </span>{getItemName(item)}</>) : (diff --git a/apps/browser-extension/src/entrypoints/popup/components/Items/ItemNameInput.tsx b/apps/browser-extension/src/entrypoints/popup/components/Items/ItemNameInput.tsxindex 000346818..77a5d5287 100644--- a/apps/browser-extension/src/entrypoints/popup/components/Items/ItemNameInput.tsx+++ b/apps/browser-extension/src/entrypoints/popup/components/Items/ItemNameInput.tsx@@ -1,9 +1,13 @@-import React, { useState, useCallback } from 'react';+import React, { useState, useCallback, useMemo } from 'react';import { useTranslation } from 'react-i18next';+import { buildFolderTree, type FolderTreeNode } from '@/utils/folderUtils';+type Folder = {Id: string;Name: string;+ ParentFolderId: string | null;+ Weight: number;};type ItemNameInputProps = {@@ -29,9 +33,28 @@ const ItemNameInput: React.FC<ItemNameInputProps> = ({}) => {const { t } = useTranslation();const [showFolderModal, setShowFolderModal] = useState(false);+ const [expandedFolders, setExpandedFolders] = useState<Set<string>>(new Set());const selectedFolder = folders.find(f => f.Id === selectedFolderId);+ // Build folder tree+ const folderTree = useMemo(() => buildFolderTree(folders), [folders]);++ /**+ * Toggle folder expansion in tree view.+ */+ const toggleFolder = useCallback((folderId: string): void => {+ setExpandedFolders(prev => {+ const next = new Set(prev);+ if (next.has(folderId)) {+ next.delete(folderId);+ } else {+ next.add(folderId);+ }+ return next;+ });+ }, []);+/*** Handle folder selection and close the modal.*/@@ -61,6 +84,77 @@ const ItemNameInput: React.FC<ItemNameInputProps> = ({setShowFolderModal(false);}, []);+ /**+ * Render a folder tree node recursively.+ */+ const renderFolderNode = useCallback((node: FolderTreeNode, depth: number = 0): React.ReactNode => {+ const isExpanded = expandedFolders.has(node.Id);+ const hasChildren = node.children.length > 0;+ const isSelected = selectedFolderId === node.Id;++ return (+ <div key={node.Id}>+ <button+ type="button"+ onClick={() => handleSelectFolder(node.Id)}+ className={`w-full px-3 py-2 text-left rounded-md flex items-center gap-2 transition-colors ${+ isSelected+ ? 'bg-primary-50 dark:bg-primary-900/20 text-primary-700 dark:text-primary-300'+ : 'text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-700'+ }`}+ style={{ paddingLeft: `${depth * 12 + 12}px` }}+ >+ {/* Expand/Collapse button */}+ {hasChildren && (+ <button+ type="button"+ onClick={(e) => {+ e.stopPropagation();+ toggleFolder(node.Id);+ }}+ className="p-0.5 hover:bg-gray-200 dark:hover:bg-gray-600 rounded transition-colors"+ >+ <svg+ className={`w-3 h-3 transition-transform ${isExpanded ? 'rotate-90' : ''}`}+ fill="currentColor"+ viewBox="0 0 20 20"+ >+ <path fillRule="evenodd" d="M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z" clipRule="evenodd" />+ </svg>+ </button>+ )}++ {/* Folder icon */}+ <svg+ className={`w-5 h-5 shrink-0 ${isSelected ? 'text-primary-500' : 'text-gray-400'} ${!hasChildren ? 'ml-5' : ''}`}+ fill="none"+ stroke="currentColor"+ viewBox="0 0 24 24"+ >+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z" />+ </svg>++ {/* Folder name */}+ <span className="font-medium flex-1">{node.Name}</span>++ {/* Checkmark for selected */}+ {isSelected && (+ <svg className="w-5 h-5 text-primary-600 dark:text-primary-400" fill="currentColor" viewBox="0 0 20 20">+ <path fillRule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clipRule="evenodd" />+ </svg>+ )}+ </button>++ {/* Render children if expanded */}+ {hasChildren && isExpanded && (+ <div>+ {node.children.map(child => renderFolderNode(child, depth + 1))}+ </div>+ )}+ </div>+ );+ }, [expandedFolders, selectedFolderId, handleSelectFolder, toggleFolder]);+return (<><div>@@ -131,7 +225,7 @@ const ItemNameInput: React.FC<ItemNameInputProps> = ({</h3></div>- {/* Folder Options */}+ {/* Folder Options - Tree View */}<div className="space-y-1 max-h-64 overflow-y-auto">{/* No Folder Option */}<button@@ -154,29 +248,8 @@ const ItemNameInput: React.FC<ItemNameInputProps> = ({)}</button>- {/* Folder Options */}- {folders.map(folder => (- <button- key={folder.Id}- type="button"- onClick={() => handleSelectFolder(folder.Id)}- className={`w-full px-3 py-2 text-left rounded-md flex items-center gap-3 transition-colors ${- selectedFolderId === folder.Id- ? 'bg-primary-50 dark:bg-primary-900/20 text-primary-700 dark:text-primary-300'- : 'text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-700'- }`}- >- <svg className={`w-5 h-5 ${selectedFolderId === folder.Id ? 'text-primary-500' : 'text-gray-400'}`} fill="none" stroke="currentColor" viewBox="0 0 24 24">- <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z" />- </svg>- <span className="font-medium">{folder.Name}</span>- {selectedFolderId === folder.Id && (- <svg className="w-5 h-5 ml-auto text-primary-600 dark:text-primary-400" fill="currentColor" viewBox="0 0 20 20">- <path fillRule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clipRule="evenodd" />- </svg>- )}- </button>- ))}+ {/* Folder Tree */}+ {folderTree.map(node => renderFolderNode(node, 0))}</div></div></div>diff --git a/apps/browser-extension/src/entrypoints/popup/pages/items/ItemsList.tsx b/apps/browser-extension/src/entrypoints/popup/pages/items/ItemsList.tsxindex 6adcc9af6..1dfa59867 100644--- a/apps/browser-extension/src/entrypoints/popup/pages/items/ItemsList.tsx+++ b/apps/browser-extension/src/entrypoints/popup/pages/items/ItemsList.tsx@@ -3,6 +3,7 @@ import { useTranslation } from 'react-i18next';import { useLocation, useNavigate, useParams, useSearchParams } from 'react-router-dom';import DeleteFolderModal from '@/entrypoints/popup/components/Folders/DeleteFolderModal';+import FolderBreadcrumb from '@/entrypoints/popup/components/Folders/FolderBreadcrumb';import FolderModal from '@/entrypoints/popup/components/Folders/FolderModal';import HeaderButton from '@/entrypoints/popup/components/HeaderButton';import { HeaderIconType } from '@/entrypoints/popup/components/Icons/HeaderIcons';@@ -19,6 +20,7 @@ import { useVaultMutate } from '@/entrypoints/popup/hooks/useVaultMutate';import { useVaultSync } from '@/entrypoints/popup/hooks/useVaultSync';import { PopoutUtility } from '@/entrypoints/popup/utils/PopoutUtility';+import type { Folder } from '@/utils/db/repositories/FolderRepository';import type { CredentialSortOrder } from '@/utils/db/repositories/SettingsRepository';import type { Item, ItemType } from '@/utils/dist/core/models/vault';import { ItemTypes } from '@/utils/dist/core/models/vault';@@ -218,6 +220,7 @@ const ItemsList: React.FC = () => {/*** Handle save folder.+ * Creates folder in current location (root or inside current folder).*/const handleSaveFolder = useCallback(async (folderName: string) : Promise<void> => {if (!dbContext?.sqliteClient) {@@ -226,6 +229,7 @@ const ItemsList: React.FC = () => {}await executeVaultMutationAsync(async () => {+ // Create folder in current location (currentFolderId = null means root)await dbContext.sqliteClient!.folders.create(folderName, currentFolderId);});@@ -429,11 +433,13 @@ const ItemsList: React.FC = () => {}, [navigate]);/**- * Get folders with item counts (only for root level when not searching)+ * Get folders with item counts.+ * - At root level: show only root folders (ParentFolderId IS NULL)+ * - Inside a folder: show only direct subfolders (ParentFolderId = currentFolderId)*/const getFoldersWithCounts = (): FolderWithCount[] => {- if (currentFolderId || searchTerm) {- return [];+ if (searchTerm) {+ return []; // Don't show folders when searching}if (!dbContext?.sqliteClient) {@@ -443,6 +449,20 @@ const ItemsList: React.FC = () => {// Get all folders directly from the databaseconst allFolders = dbContext.sqliteClient.folders.getAll();+ // Filter folders based on current location+ const relevantFolders = allFolders.filter((folder: Folder) => {+ if (currentFolderId) {+ // Inside a folder: show only direct children+ return folder.ParentFolderId === currentFolderId;+ } else {+ /*+ * At root: show only root-level folders+ * Check for both null and undefined since SQLite might return either+ */+ return folder.ParentFolderId === null || folder.ParentFolderId === undefined;+ }+ });+// Count items per folderconst folderCounts = new Map<string, number>();items.forEach((item: Item) => {@@ -452,7 +472,7 @@ const ItemsList: React.FC = () => {});// Build result with counts- const result = allFolders.map((folder: { Id: string; Name: string }) => ({+ const result = relevantFolders.map((folder: Folder) => ({id: folder.Id,name: folder.Name,itemCount: folderCounts.get(folder.Id) || 0@@ -564,6 +584,9 @@ const ItemsList: React.FC = () => {return (<div>+ {/* Breadcrumb navigation - only show when inside a folder */}+ <FolderBreadcrumb folderId={currentFolderId} refreshKey={folderRefreshKey} />+<div className="flex justify-between items-center gap-2 mb-4"><div className="relative min-w-0 flex-1 flex items-center gap-2"><button@@ -833,7 +856,7 @@ const ItemsList: React.FC = () => {</p></div></>- ) : filteredItems.length === 0 && folders.length === 0 && !hasItemsInFoldersOnly ? (+ ) : filteredItems.length === 0 && folders.length === 0 && !hasItemsInFoldersOnly && !currentFolderId ? (<div className="text-gray-500 dark:text-gray-400 space-y-3 mb-10">{/* Show filter/search-specific messages only when actively filtering or searching */}{(filterType !== 'all' || searchTerm) && (@@ -884,12 +907,6 @@ const ItemsList: React.FC = () => {</div></>)}- {/* Show help text when inside an empty folder */}- {currentFolderId && (- <p className="text-sm">- {t('items.emptyFolderHint')}- </p>- )}</div>) : hasItemsInFoldersOnly && filteredItems.length === 0 && !currentFolderId && !searchTerm ? (/* Show message when all items are in folders and we're at root level */@@ -922,8 +939,10 @@ const ItemsList: React.FC = () => {</>) : (<>- {/* Folders as inline pills (only show at root level when not searching and showFolders is enabled) */}- {!currentFolderId && !searchTerm && showFolders && (+ {/* Folders as inline pills - show when not searching */}+ {/* At root: show only if showFolders is enabled */}+ {/* Inside folder: always show subfolders and create button */}+ {!searchTerm && (currentFolderId || showFolders) && (<div className="flex flex-wrap items-center gap-2 mb-4">{folders.map(folder => (<FolderPill@@ -972,6 +991,13 @@ const ItemsList: React.FC = () => {</ul>)}+ {/* Show help text when inside an empty folder with no items */}+ {currentFolderId && sortedItems.length === 0 && !searchTerm && (+ <div className="text-gray-500 dark:text-gray-400 text-sm mb-4">+ <p>{t('items.emptyFolderHint')}</p>+ </div>+ )}+{/* Clear filter/search pills at bottom of list when filtering or searching */}{(filterType !== 'all' || searchTerm) && (<div className="flex flex-wrap justify-center gap-2 mt-4 pt-4">diff --git a/apps/browser-extension/src/utils/db/queries/ItemQueries.ts b/apps/browser-extension/src/utils/db/queries/ItemQueries.tsindex 5fdfe2657..5fd94e614 100644--- a/apps/browser-extension/src/utils/db/queries/ItemQueries.ts+++ b/apps/browser-extension/src/utils/db/queries/ItemQueries.ts@@ -5,15 +5,40 @@export class ItemQueries {/*** Base SELECT for items with common fields.- * Includes LEFT JOIN to Logos and Folders, and subqueries for HasPasskey/HasAttachment/HasTotp.+ * Includes LEFT JOIN to Logos and recursive CTE for full folder paths.+ * Builds hierarchical folder paths like "Work > Projects > AliasVault".*/public static readonly BASE_SELECT = `+ WITH RECURSIVE FolderPath AS (+ -- Base case: root folders (no parent)+ SELECT+ Id,+ Name,+ ParentFolderId,+ Name as Path,+ 0 as Depth+ FROM Folders+ WHERE ParentFolderId IS NULL AND IsDeleted = 0++ UNION ALL++ -- Recursive case: child folders+ SELECT+ f.Id,+ f.Name,+ f.ParentFolderId,+ fp.Path || ' > ' || f.Name as Path,+ fp.Depth + 1 as Depth+ FROM Folders f+ INNER JOIN FolderPath fp ON f.ParentFolderId = fp.Id+ WHERE f.IsDeleted = 0 AND fp.Depth < 10+ )SELECT DISTINCTi.Id,i.Name,i.ItemType,i.FolderId,- f.Name as FolderPath,+ fp.Path as FolderPath,l.FileData as Logo,CASE WHEN EXISTS (SELECT 1 FROM Passkeys pk WHERE pk.ItemId = i.Id AND pk.IsDeleted = 0) THEN 1 ELSE 0 END as HasPasskey,CASE WHEN EXISTS (SELECT 1 FROM Attachments att WHERE att.ItemId = i.Id AND att.IsDeleted = 0) THEN 1 ELSE 0 END as HasAttachment,@@ -22,7 +47,7 @@ export class ItemQueries {i.UpdatedAtFROM Items iLEFT JOIN Logos l ON i.LogoId = l.Id- LEFT JOIN Folders f ON i.FolderId = f.Id`;+ LEFT JOIN FolderPath fp ON i.FolderId = fp.Id`;/*** Get all active items (not deleted, not in trash).@@ -55,11 +80,44 @@ export class ItemQueries {* Get all recently deleted items (in trash).*/public static readonly GET_RECENTLY_DELETED = `- ${ItemQueries.BASE_SELECT},+ WITH RECURSIVE FolderPath AS (+ SELECT+ Id,+ Name,+ ParentFolderId,+ Name as Path,+ 0 as Depth+ FROM Folders+ WHERE ParentFolderId IS NULL AND IsDeleted = 0++ UNION ALL++ SELECT+ f.Id,+ f.Name,+ f.ParentFolderId,+ fp.Path || ' > ' || f.Name as Path,+ fp.Depth + 1 as Depth+ FROM Folders f+ INNER JOIN FolderPath fp ON f.ParentFolderId = fp.Id+ WHERE f.IsDeleted = 0 AND fp.Depth < 10+ )+ SELECT DISTINCT+ i.Id,+ i.Name,+ i.ItemType,+ i.FolderId,+ fp.Path as FolderPath,+ l.FileData as Logo,+ CASE WHEN EXISTS (SELECT 1 FROM Passkeys pk WHERE pk.ItemId = i.Id AND pk.IsDeleted = 0) THEN 1 ELSE 0 END as HasPasskey,+ CASE WHEN EXISTS (SELECT 1 FROM Attachments att WHERE att.ItemId = i.Id AND att.IsDeleted = 0) THEN 1 ELSE 0 END as HasAttachment,+ CASE WHEN EXISTS (SELECT 1 FROM TotpCodes tc WHERE tc.ItemId = i.Id AND tc.IsDeleted = 0) THEN 1 ELSE 0 END as HasTotp,+ i.CreatedAt,+ i.UpdatedAt,i.DeletedAtFROM Items iLEFT JOIN Logos l ON i.LogoId = l.Id- LEFT JOIN Folders f ON i.FolderId = f.Id+ LEFT JOIN FolderPath fp ON i.FolderId = fp.IdWHERE i.IsDeleted = 0 AND i.DeletedAt IS NOT NULLORDER BY i.DeletedAt DESC`;diff --git a/apps/browser-extension/src/utils/folderUtils.ts b/apps/browser-extension/src/utils/folderUtils.tsnew file mode 100644index 000000000..b368f1730--- /dev/null+++ b/apps/browser-extension/src/utils/folderUtils.ts@@ -0,0 +1,296 @@+import type { Folder } from './db/repositories/FolderRepository';++/**+ * Maximum allowed folder nesting depth.+ */+export const MAX_FOLDER_DEPTH = 5;++/**+ * Folder tree node with hierarchical structure.+ */+export type FolderTreeNode = Folder & {+ children: FolderTreeNode[];+ depth: number;+ path: string[]; // Array of folder IDs from root to this folder+};++/**+ * Build a hierarchical tree from a flat array of folders.+ * @param folders - Flat array of folders+ * @returns Array of root-level folder tree nodes+ */+export function buildFolderTree(folders: Folder[]): FolderTreeNode[] {+ // Create a map for quick lookup+ const folderMap = new Map<string, FolderTreeNode>();++ // Initialize all folders as tree nodes+ folders.forEach(folder => {+ folderMap.set(folder.Id, {+ ...folder,+ children: [],+ depth: 0,+ path: []+ });+ });++ // Build the tree structure+ const rootFolders: FolderTreeNode[] = [];++ folders.forEach(folder => {+ const node = folderMap.get(folder.Id)!;++ if (!folder.ParentFolderId) {+ // Root folder+ node.depth = 0;+ node.path = [folder.Id];+ rootFolders.push(node);+ } else {+ // Child folder+ const parent = folderMap.get(folder.ParentFolderId);+ if (parent) {+ node.depth = parent.depth + 1;+ node.path = [...parent.path, folder.Id];+ parent.children.push(node);+ } else {+ // Parent not found or deleted - treat as root+ node.depth = 0;+ node.path = [folder.Id];+ rootFolders.push(node);+ }+ }+ });++ /**+ * Sort children of a folder tree node recursively.+ */+ const sortChildren = (nodes: FolderTreeNode[]): void => {+ nodes.sort((a, b) => {+ // Sort by weight first, then by name (case-insensitive)+ if (a.Weight !== b.Weight) {+ return a.Weight - b.Weight;+ }+ return a.Name.localeCompare(b.Name, undefined, { sensitivity: 'base' });+ });+ nodes.forEach(node => sortChildren(node.children));+ };++ sortChildren(rootFolders);++ return rootFolders;+}++/**+ * Get folder depth in the hierarchy.+ * @param folderId - The folder ID to check+ * @param folders - Flat array of all folders+ * @returns Depth (0 = root, 1 = one level deep, etc.) or null if folder not found+ */+export function getFolderDepth(folderId: string, folders: Folder[]): number | null {+ const folder = folders.find(f => f.Id === folderId);+ if (!folder) {+ return null;+ }++ let depth = 0;+ let currentId: string | null = folderId;++ // Traverse up to root, counting levels+ while (currentId) {+ const current = folders.find(f => f.Id === currentId);+ if (!current || !current.ParentFolderId) {+ break;+ }+ depth++;+ currentId = current.ParentFolderId;++ // Prevent infinite loops+ if (depth > MAX_FOLDER_DEPTH) {+ break;+ }+ }++ return depth;+}++/**+ * Get the full path of folder names from root to the specified folder.+ * @param folderId - The folder ID+ * @param folders - Flat array of all folders+ * @returns Array of folder names from root to current folder, or empty array if not found+ */+export function getFolderPath(folderId: string | null, folders: Folder[]): string[] {+ if (!folderId) {+ return [];+ }++ const path: string[] = [];+ let currentId: string | null = folderId;+ let iterations = 0;++ // Build path by traversing up to root+ while (currentId && iterations < MAX_FOLDER_DEPTH + 1) {+ const folder = folders.find(f => f.Id === currentId);+ if (!folder) {+ break;+ }+ path.unshift(folder.Name); // Add to beginning of array+ currentId = folder.ParentFolderId;+ iterations++;+ }++ return path;+}++/**+ * Get the full path of folder IDs from root to the specified folder.+ * @param folderId - The folder ID+ * @param folders - Flat array of all folders+ * @returns Array of folder IDs from root to current folder, or empty array if not found+ */+export function getFolderIdPath(folderId: string | null, folders: Folder[]): string[] {+ if (!folderId) {+ return [];+ }++ const path: string[] = [];+ let currentId: string | null = folderId;+ let iterations = 0;++ // Build path by traversing up to root+ while (currentId && iterations < MAX_FOLDER_DEPTH + 1) {+ const folder = folders.find(f => f.Id === currentId);+ if (!folder) {+ break;+ }+ path.unshift(folder.Id); // Add to beginning of array+ currentId = folder.ParentFolderId;+ iterations++;+ }++ return path;+}++/**+ * Truncate a folder path for display, keeping first and last segments.+ * Example: "Work > Projects > Client A > Project X > Credentials" -> "Work > ... > Credentials"+ * @param pathSegments - Array of folder names+ * @param maxSegments - Maximum number of segments to show (default: 3)+ * @returns Truncated path segments+ */+export function truncateFolderPath(pathSegments: string[], maxSegments: number = 3): string[] {+ if (pathSegments.length <= maxSegments) {+ return pathSegments;+ }++ // Show first segment, "...", and last segment+ if (maxSegments === 2) {+ return [pathSegments[0], '...', pathSegments[pathSegments.length - 1]];+ }++ // Show first 2 segments, "...", and last segment+ if (maxSegments === 3) {+ return [pathSegments[0], '...', pathSegments[pathSegments.length - 1]];+ }++ // For more segments, distribute them+ const firstCount = Math.ceil((maxSegments - 1) / 2);+ const lastCount = Math.floor((maxSegments - 1) / 2);++ return [+ ...pathSegments.slice(0, firstCount),+ '...',+ ...pathSegments.slice(-lastCount)+ ];+}++/**+ * Format folder path for display with separator.+ * @param pathSegments - Array of folder names+ * @param separator - Separator string (default: " > ")+ * @param truncate - Whether to truncate long paths (default: false)+ * @returns Formatted folder path string+ */+export function formatFolderPath(+ pathSegments: string[],+ separator: string = ' > ',+ truncate: boolean = false+): string {+ const segments = truncate ? truncateFolderPath(pathSegments) : pathSegments;+ return segments.join(separator);+}++/**+ * Flatten a folder tree into a sorted array suitable for dropdowns.+ * Includes visual indentation in the name.+ * @param tree - Root-level folder tree nodes+ * @param excludeId - Optional folder ID to exclude (useful when moving folders)+ * @returns Flat array of folders with indented names+ */+export function flattenFolderTree(+ tree: FolderTreeNode[],+ excludeId?: string+): Array<Folder & { indentedName: string; depth: number }> {+ const result: Array<Folder & { indentedName: string; depth: number }> = [];++ /**+ * Traverse a folder tree and flatten it into a sorted array.+ */+ const traverse = (nodes: FolderTreeNode[]): void => {+ nodes.forEach(node => {+ if (node.Id === excludeId) {+ return; // Skip excluded folder and its children+ }++ const indent = ' '.repeat(node.depth); // Two spaces per level+ result.push({+ Id: node.Id,+ Name: node.Name,+ ParentFolderId: node.ParentFolderId,+ Weight: node.Weight,+ indentedName: `${indent}${node.Name}`,+ depth: node.depth+ });++ traverse(node.children);+ });+ };++ traverse(tree);+ return result;+}++/**+ * Check if a folder can have subfolders (not at max depth).+ * @param folderId - The folder ID to check+ * @param folders - Flat array of all folders+ * @returns True if folder can have children, false otherwise+ */+export function canHaveSubfolders(folderId: string, folders: Folder[]): boolean {+ const depth = getFolderDepth(folderId, folders);+ return depth !== null && depth < MAX_FOLDER_DEPTH;+}++/**+ * Get all descendant folder IDs (children, grandchildren, etc.).+ * @param folderId - The parent folder ID+ * @param folders - Flat array of all folders+ * @returns Array of descendant folder IDs+ */+export function getDescendantFolderIds(folderId: string, folders: Folder[]): string[] {+ const descendants: string[] = [];++ /**+ * Traverse a folder tree and get all descendant folder IDs.+ */+ const traverse = (parentId: string): void => {+ folders+ .filter(f => f.ParentFolderId === parentId)+ .forEach(child => {+ descendants.push(child.Id);+ traverse(child.Id);+ });+ };++ traverse(folderId);+ return descendants;+}diff --git a/apps/server/AliasVault.Client/wwwroot/css/tailwind.css b/apps/server/AliasVault.Client/wwwroot/css/tailwind.cssindex 2dedffd63..ec623fe51 100644--- a/apps/server/AliasVault.Client/wwwroot/css/tailwind.css+++ b/apps/server/AliasVault.Client/wwwroot/css/tailwind.css@@ -2013,6 +2013,11 @@ video {background-color: rgb(234 179 8 / var(--tw-bg-opacity));}+.bg-orange-600 {+ --tw-bg-opacity: 1;+ background-color: rgb(234 88 12 / var(--tw-bg-opacity));+}+.bg-opacity-50 {--tw-bg-opacity: 0.5;}@@ -2915,6 +2920,11 @@ video {background-color: rgb(153 27 27 / var(--tw-bg-opacity));}+.hover\:bg-orange-500:hover {+ --tw-bg-opacity: 1;+ background-color: rgb(249 115 22 / var(--tw-bg-opacity));+}+.hover\:from-primary-600:hover {--tw-gradient-from: #d68338 var(--tw-gradient-from-position);--tw-gradient-to: rgb(214 131 56 / 0) var(--tw-gradient-to-position);@@ -3471,6 +3481,15 @@ video {background-color: rgb(113 63 18 / 0.2);}+.dark\:bg-blue-800\/30:is(.dark *) {+ background-color: rgb(30 64 175 / 0.3);+}++.dark\:bg-orange-700:is(.dark *) {+ --tw-bg-opacity: 1;+ background-color: rgb(194 65 12 / var(--tw-bg-opacity));+}+.dark\:bg-opacity-75:is(.dark *) {--tw-bg-opacity: 0.75;}@@ -3652,6 +3671,11 @@ video {color: rgb(250 204 21 / var(--tw-text-opacity));}+.dark\:text-blue-300:is(.dark *) {+ --tw-text-opacity: 1;+ color: rgb(147 197 253 / var(--tw-text-opacity));+}+.dark\:placeholder-gray-400:is(.dark *)::-moz-placeholder {--tw-placeholder-opacity: 1;color: rgb(156 163 175 / var(--tw-placeholder-opacity));@@ -3786,6 +3810,11 @@ video {background-color: rgb(127 29 29 / 0.5);}+.dark\:hover\:bg-orange-600:hover:is(.dark *) {+ --tw-bg-opacity: 1;+ background-color: rgb(234 88 12 / var(--tw-bg-opacity));+}+.dark\:hover\:from-primary-500:hover:is(.dark *) {--tw-gradient-from: #f49541 var(--tw-gradient-from-position);--tw-gradient-to: rgb(244 149 65 / 0) var(--tw-gradient-to-position);