Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Add item display components (#2413)

Leendert de Borstdc76dfc4175f
diff --git a/apps/web/src/components/items/DisplayField.ts b/apps/web/src/components/items/DisplayField.ts
new file mode 100644
index 000000000..e4ea2dfcb
--- /dev/null
+++ b/apps/web/src/components/items/DisplayField.ts
@@ -0,0 +1,140 @@
+import { FieldKey, FieldTypes, getSystemField, type FieldCategory, FieldCategories, type Item, type ItemField } from '@aliasvault/models/vault';
+
+/**
+ * A single value of an item field as shown on the item page. A multi-value field renders one display field per value.
+ */
+export type DisplayField = {
+ FieldKey: string;
+ Label: string;
+ FieldType: string;
+ IsCustomField: boolean;
+ Value: string;
+ IsHidden: boolean;
+ EnableHistory: boolean;
+ DisplayOrder: number;
+ Category: FieldCategory;
+};
+
+/**
+ * The category of a field, from the system field registry; unknown keys are custom.
+ */
+const getCategory = (field: ItemField): FieldCategory => {
+ if (field.IsCustomField) {
+ return FieldCategories.Custom;
+ }
+ return getSystemField(field.FieldKey)?.Category ?? FieldCategories.Custom;
+};
+
+/**
+ * The values of a field, one entry per non-empty value.
+ */
+const valuesOf = (field: ItemField): string[] => {
+ const values = Array.isArray(field.Value) ? field.Value : [field.Value];
+ return values.filter(v => typeof v === 'string' && v.length > 0);
+};
+
+/**
+ * The order of a login field on the item page: email, username, password, then the rest.
+ */
+const loginOrder = (field: DisplayField): number => {
+ switch (field.FieldKey) {
+ case FieldKey.LoginEmail: return 1;
+ case FieldKey.LoginUsername: return 2;
+ case FieldKey.LoginPassword: return 3;
+ default: return 4 + field.DisplayOrder;
+ }
+};
+
+/**
+ * Group the non-empty field values of an item by category, in display order.
+ */
+export function groupDisplayFields(item: Item): Record<FieldCategory, DisplayField[]> {
+ const result = Object.fromEntries(Object.values(FieldCategories).map(c => [c, [] as DisplayField[]])) as Record<FieldCategory, DisplayField[]>;
+
+ for (const field of item.Fields) {
+ const category = getCategory(field);
+ const systemField = field.IsCustomField ? undefined : getSystemField(field.FieldKey);
+ for (const value of valuesOf(field)) {
+ result[category].push({
+ FieldKey: field.FieldKey,
+ Label: field.IsCustomField ? field.Label : field.FieldKey,
+ FieldType: field.FieldType ?? FieldTypes.Text,
+ IsCustomField: field.IsCustomField,
+ Value: value,
+ IsHidden: field.IsHidden,
+ EnableHistory: field.EnableHistory,
+ DisplayOrder: systemField?.DefaultDisplayOrder ?? field.DisplayOrder,
+ Category: category,
+ });
+ }
+ }
+
+ for (const category of Object.keys(result) as FieldCategory[]) {
+ result[category].sort((a, b) => a.DisplayOrder - b.DisplayOrder);
+ }
+ result[FieldCategories.Login].sort((a, b) => loginOrder(a) - loginOrder(b));
+
+ return result;
+}
+
+/**
+ * The URL values of an item, for the header block.
+ */
+export function getUrlValues(item: Item): string[] {
+ const field = item.Fields.find(f => f.FieldKey === FieldKey.LoginUrl);
+ return field ? valuesOf(field) : [];
+}
+
+/** Field types that always span the full width. */
+const ALWAYS_FULL_WIDTH_TYPES: string[] = [FieldTypes.Password, FieldTypes.Hidden, FieldTypes.TextArea, FieldTypes.URL];
+
+/** Field keys that always span the full width. */
+const ALWAYS_FULL_WIDTH_KEYS: string[] = [FieldKey.CardCardholderName];
+
+/** Field pairs that sit next to each other at half width when both are present. */
+const PINNED_HALF_WIDTH_PAIRS: [string, string][] = [
+ [FieldKey.CardExpiryMonth, FieldKey.CardExpiryYear],
+ [FieldKey.CardCvv, FieldKey.CardPin],
+];
+
+/**
+ * Which fields of a section span the full width.
+ */
+function getFullWidthFields(fields: DisplayField[]): Set<string> {
+ const fullWidth = new Set<string>();
+ const keys = new Set(fields.map(f => f.FieldKey));
+ const pinnedHalf = new Set<string>();
+ for (const [a, b] of PINNED_HALF_WIDTH_PAIRS) {
+ if (keys.has(a) && keys.has(b)) {
+ pinnedHalf.add(a);
+ pinnedHalf.add(b);
+ }
+ }
+
+ const candidates: DisplayField[] = [];
+ for (const field of fields) {
+ if (pinnedHalf.has(field.FieldKey)) {
+ continue;
+ }
+ if (ALWAYS_FULL_WIDTH_TYPES.includes(field.FieldType) || ALWAYS_FULL_WIDTH_KEYS.includes(field.FieldKey)) {
+ fullWidth.add(field.FieldKey);
+ } else {
+ candidates.push(field);
+ }
+ }
+
+ if (candidates.length === 1) {
+ fullWidth.add(candidates[0].FieldKey);
+ } else if (candidates.length > 1 && candidates.length % 2 === 1) {
+ fullWidth.add(candidates[candidates.length - 1].FieldKey);
+ }
+
+ return fullWidth;
+}
+
+/**
+ * Whether a field spans the full width of its section.
+ */
+export function shouldBeFullWidth(field: DisplayField, fields: DisplayField[]): boolean {
+ return getFullWidthFields(fields).has(field.FieldKey);
+}
diff --git a/apps/web/src/components/items/FieldHistoryModal.tsx b/apps/web/src/components/items/FieldHistoryModal.tsx
new file mode 100644
index 000000000..e7a7fb5d0
--- /dev/null
+++ b/apps/web/src/components/items/FieldHistoryModal.tsx
@@ -0,0 +1,158 @@
+import React, { useCallback, useEffect, useRef, useState } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import CopyPasteFormRow from '@/components/forms/CopyPasteFormRow';
+import CopyPastePasswordFormRow from '@/components/forms/CopyPastePasswordFormRow';
+import { useDb } from '@/context/DbContext';
+import { useClickOutside } from '@/hooks/useClickOutside';
+import { useVaultMutate } from '@/hooks/useVaultMutate';
+
+import type { ItemRef } from '@aliasvault/client/database/ItemRef';
+import type { FieldHistory } from '@aliasvault/models/vault';
+
+type FieldHistoryModalProps = {
+ item: ItemRef;
+ fieldKey: string;
+ fieldLabel: string;
+ isHidden: boolean;
+ onClose: () => void;
+};
+
+/**
+ * The values in a history snapshot, or the raw snapshot when it is not a JSON list.
+ */
+const parseValueSnapshot = (snapshot: string): string[] => {
+ try {
+ const values: unknown = JSON.parse(snapshot);
+ return Array.isArray(values) ? values.map(String) : [snapshot];
+ } catch {
+ return [snapshot];
+ }
+};
+
+/**
+ * "MMM d, yyyy h:mm tt".
+ */
+const formatDate = (value: string): string => new Date(value).toLocaleString('en-US', { month: 'short', day: 'numeric', year: 'numeric', hour: 'numeric', minute: '2-digit' });
+
+/**
+ * Modal listing the past values of a field.
+ */
+const FieldHistoryModal: React.FC<FieldHistoryModalProps> = ({ item, fieldKey, fieldLabel, isHidden, onClose }) => {
+ const { t } = useTranslation();
+ const dbContext = useDb();
+ const { executeVaultMutationAsync } = useVaultMutate();
+ const [isLoading, setIsLoading] = useState(true);
+ const [records, setRecords] = useState<FieldHistory[]>([]);
+ const [confirmDeleteId, setConfirmDeleteId] = useState<string | null>(null);
+ const panelRef = useRef<HTMLDivElement>(null);
+
+ useClickOutside([panelRef], onClose, true);
+
+ /**
+ * Load the history records.
+ */
+ const loadHistory = useCallback((): void => {
+ setIsLoading(true);
+ setRecords(dbContext.sqliteClient?.items.getFieldHistory({ Id: item.Id, ManifestId: item.ManifestId }, fieldKey) ?? []);
+ setIsLoading(false);
+ }, [dbContext.sqliteClient, fieldKey, item.Id, item.ManifestId]);
+
+ useEffect(() => loadHistory(), [loadHistory]);
+
+ useEffect(() => {
+ /**
+ * Escape and Enter close the modal.
+ */
+ const onKeyDown = (event: KeyboardEvent): void => {
+ if (event.key === 'Escape' || event.key === 'Enter') {
+ onClose();
+ }
+ };
+ document.addEventListener('keydown', onKeyDown);
+ return (): void => document.removeEventListener('keydown', onKeyDown);
+ }, [onClose]);
+
+ /**
+ * Delete a history record and sync.
+ */
+ const deleteRecord = async (historyId: string): Promise<void> => {
+ await executeVaultMutationAsync(async () => {
+ await dbContext.sqliteClient?.items.deleteFieldHistory(historyId, item.ManifestId);
+ });
+ setConfirmDeleteId(null);
+ loadHistory();
+ };
+
+ return (
+ <div className="modal-dialog fixed inset-0 z-50 overflow-auto bg-gray-500 bg-opacity-75 flex items-center justify-center">
+ <div ref={panelRef} id="fieldHistoryModal" className="relative bg-white dark:bg-gray-800 w-full max-w-2xl flex flex-col rounded-lg shadow-xl max-h-[90vh] border-2 border-gray-300 dark:border-gray-600">
+ <div className="p-4 border-b border-gray-200 dark:border-gray-700">
+ <div className="flex items-center justify-between">
+ <h2 className="text-xl font-bold text-gray-900 dark:text-white">
+ {t('components.fields.fieldHistoryModal.HistoryTitle')} - {fieldLabel}
+ </h2>
+ <button type="button" onClick={onClose} className="text-gray-400 hover:text-gray-500 dark:hover:text-gray-300" title={t('sharedResources.Close')} aria-label={t('sharedResources.Close')}>
+ <svg className="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M6 18L18 6M6 6l12 12" />
+ </svg>
+ </button>
+ </div>
+ </div>
+
+ <div className="flex-1 overflow-y-auto p-4">
+ {isLoading ? (
+ <div className="flex justify-center items-center py-8">
+ <svg className="animate-spin h-8 w-8 text-gray-500" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
+ <circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4"></circle>
+ <path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
+ </svg>
+ </div>
+ ) : records.length === 0 ? (
+ <p className="text-gray-500 dark:text-gray-400 text-center py-8">{t('components.fields.fieldHistoryModal.NoHistoryAvailable')}</p>
+ ) : (
+ <div className="space-y-4">
+ {records.map((record) => {
+ const values = parseValueSnapshot(record.ValueSnapshot);
+ return (
+ <div key={record.Id} className="border border-gray-200 dark:border-gray-700 rounded-lg p-4">
+ <div className="flex items-center justify-between mb-2">
+ <div className="text-sm text-gray-500 dark:text-gray-400">{formatDate(record.ChangedAt)}</div>
+ {confirmDeleteId === record.Id ? (
+ <div className="flex items-center gap-2">
+ <span className="text-xs text-gray-500 dark:text-gray-400">{t('components.fields.fieldHistoryModal.DeleteConfirm')}</span>
+ <button type="button" onClick={() => void deleteRecord(record.Id)} className="text-xs px-2 py-1 text-red-600 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300 font-medium">
+ {t('sharedResources.Confirm')}
+ </button>
+ <button type="button" onClick={() => setConfirmDeleteId(null)} className="text-xs px-2 py-1 text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200">
+ {t('sharedResources.Cancel')}
+ </button>
+ </div>
+ ) : (
+ <button type="button" onClick={() => setConfirmDeleteId(record.Id)} className="text-gray-500 hover:text-red-600 dark:text-gray-400 dark:hover:text-red-400 transition-colors" title={t('sharedResources.Delete')}>
+ <svg className="h-4 w-4" fill="none" viewBox="0 0 24 24" strokeWidth="1.5" stroke="currentColor">
+ <path strokeLinecap="round" strokeLinejoin="round" d="m14.74 9-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 0 1-2.244 2.077H8.084a2.25 2.25 0 0 1-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 0 0-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 0 1 3.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 0 0-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 0 0-7.5 0" />
+ </svg>
+ </button>
+ )}
+ </div>
+ {values.map((value, index) => (
+ <div key={index} className="mb-2 last:mb-0">
+ {isHidden
+ ? <CopyPastePasswordFormRow id={`history-${record.Id}-${index}`} label="" value={value} />
+ : <CopyPasteFormRow id={`history-${record.Id}-${index}`} label="" value={value} />}
+ </div>
+ ))}
+ </div>
+ );
+ })}
+ </div>
+ )}
+ </div>
+
+ </div>
+ </div>
+ );
+};
+
+export default FieldHistoryModal;
diff --git a/apps/web/src/components/items/FolderBreadcrumbs.ts b/apps/web/src/components/items/FolderBreadcrumbs.ts
new file mode 100644
index 000000000..4a8fb3de1
--- /dev/null
+++ b/apps/web/src/components/items/FolderBreadcrumbs.ts
@@ -0,0 +1,24 @@
+import { getFolderIdPath } from '@aliasvault/client/items/FolderUtils';
+
+import type { BreadcrumbItem } from '@/components/shared/Breadcrumb';
+import { folderRoute } from '@/utils/ItemRoute';
+
+import type { Folder, FolderRef } from '@aliasvault/client/database/repositories/FolderRepository';
+
+/**
+ * Breadcrumbs for the folder chain from the root to a folder.
+ * @param ref - the folder
+ * @param folders - all folders
+ * @param makeLastClickable - whether the last folder links to itself
+ */
+export function buildFolderBreadcrumbs(ref: FolderRef, folders: Folder[], makeLastClickable: boolean = true): BreadcrumbItem[] {
+ const idPath = getFolderIdPath(ref, folders);
+ return idPath.flatMap((id, index) => {
+ const folder = folders.find(f => f.Id === id && f.ManifestId === ref.ManifestId);
+ if (!folder) {
+ return [];
+ }
+ const clickable = index < idPath.length - 1 || makeLastClickable;
+ return [{ displayName: folder.Name, url: clickable ? folderRoute(folder) : undefined }];
+ });
+}
diff --git a/apps/web/src/components/items/FolderPill.tsx b/apps/web/src/components/items/FolderPill.tsx
new file mode 100644
index 000000000..a09045089
--- /dev/null
+++ b/apps/web/src/components/items/FolderPill.tsx
@@ -0,0 +1,27 @@
+import React from 'react';
+
+/**
+ * A folder with the number of items it (recursively) holds.
+ */
+export type FolderWithCount = {
+ id: string;
+ manifestId: string;
+ name: string;
+ parentFolderId: string | null;
+ itemCount: number;
+};
+
+/**
+ * Clickable folder pill.
+ */
+const FolderPill: React.FC<{ folder: FolderWithCount; onClick: () => void }> = ({ folder, onClick }) => (
+ <button onClick={onClick} className="inline-flex items-center gap-2 px-5 py-2.5 text-sm rounded-lg bg-white dark:bg-gray-700/50 border border-gray-200 dark:border-gray-600 hover:bg-gray-50 dark:hover:bg-gray-600/50 hover:border-gray-300 dark:hover:border-gray-500 transition-colors focus:outline-none focus:ring-2 focus:ring-orange-500 focus:ring-offset-1 dark:focus:ring-offset-gray-800">
+ <svg className="w-4 h-4 text-orange-500 flex-shrink-0" viewBox="0 0 24 24" fill="currentColor">
+ <path d="M10 4H4a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-8l-2-2z" />
+ </svg>
+ <span className="text-gray-700 dark:text-gray-300 truncate max-w-[150px]" title={folder.name}>{folder.name}</span>
+ <span className="text-gray-400 dark:text-gray-500 text-xs">{folder.itemCount}</span>
+ </button>
+);
+
+export default FolderPill;
diff --git a/apps/web/src/components/items/FolderSelector.tsx b/apps/web/src/components/items/FolderSelector.tsx
new file mode 100644
index 000000000..2453ee0c4
--- /dev/null
+++ b/apps/web/src/components/items/FolderSelector.tsx
@@ -0,0 +1,213 @@
+import { scopedKey } from '@aliasvault/client/database/ItemRef';
+import { buildFolderTree, getFolderIdPath, type FolderTreeNode } from '@aliasvault/client/items/FolderUtils';
+import React, { useEffect, useMemo, useState } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import FormModal from '@/components/shared/FormModal';
+import { useDb } from '@/context/DbContext';
+
+import type { Folder, FolderRef } from '@aliasvault/client/database/repositories/FolderRepository';
+
+type FolderSelectorProps = {
+ selectedFolder: FolderRef | null;
+ onSelectedFolderChange: (folder: FolderRef | null) => void;
+ excludeFolder?: FolderRef | null;
+};
+
+/**
+ * The key of a folder in the selector's maps including the manifest id as scope.
+ */
+const folderKey = (folder: FolderRef): string => scopedKey(folder.ManifestId, folder.Id);
+
+/**
+ * Inline folder name with a modal to pick another folder from the tree.
+ */
+const FolderSelector: React.FC<FolderSelectorProps> = ({ selectedFolder, onSelectedFolderChange, excludeFolder = null }) => {
+ const { t } = useTranslation();
+ const dbContext = useDb();
+ const [folders, setFolders] = useState<Folder[]>([]);
+ const [itemCounts, setItemCounts] = useState<Record<string, number>>({});
+ const [expandedFolderIds, setExpandedFolderIds] = useState<Set<string>>(new Set());
+ const [showFolderModal, setShowFolderModal] = useState(false);
+ const tk = 'components.main.items.folderSelector';
+
+ useEffect(() => {
+ const client = dbContext.sqliteClient;
+ if (!client) {
+ return;
+ }
+ const all = client.folders.getAll();
+ setFolders(all);
+ const counts: Record<string, number> = {};
+ for (const item of client.items.getAll()) {
+ if (item.FolderId) {
+ const key = scopedKey(item.ManifestId, item.FolderId);
+ counts[key] = (counts[key] ?? 0) + 1;
+ }
+ }
+ setItemCounts(counts);
+ }, [dbContext.sqliteClient]);
+
+ // Expand the parents of the selected folder so it is visible.
+ const selectedKey = selectedFolder ? folderKey(selectedFolder) : null;
+ const excludedKey = excludeFolder ? folderKey(excludeFolder) : null;
+ useEffect(() => {
+ if (!selectedFolder || folders.length === 0) {
+ return;
+ }
+ const parentKeys = getFolderIdPath(selectedFolder, folders).filter(id => id !== selectedFolder.Id).map(id => scopedKey(selectedFolder.ManifestId, id));
+ setExpandedFolderIds(prev => new Set([...prev, ...parentKeys]));
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [folders, selectedKey]);
+
+ const tree = useMemo(() => buildFolderTree(folders), [folders]);
+
+ const flatTree = useMemo((): FolderTreeNode[] => {
+ const result: FolderTreeNode[] = [];
+ /**
+ * Walk the tree, skipping the excluded folder and collapsed children.
+ */
+ const traverse = (nodes: FolderTreeNode[]): void => {
+ for (const node of nodes) {
+ if (folderKey(node) === excludedKey) {
+ continue;
+ }
+ result.push(node);
+ if (expandedFolderIds.has(folderKey(node)) && node.children.length > 0) {
+ traverse(node.children);
+ }
+ }
+ };
+ traverse(tree);
+ return result;
+ }, [excludedKey, expandedFolderIds, tree]);
+
+ /**
+ * Expand or collapse a folder.
+ */
+ const toggleExpansion = (key: string): void => {
+ setExpandedFolderIds((prev) => {
+ const next = new Set(prev);
+ if (next.has(key)) {
+ next.delete(key);
+ } else {
+ next.add(key);
+ }
+ return next;
+ });
+ };
+
+ /**
+ * Pick a folder and close.
+ */
+ const selectFolder = (folder: FolderRef | null): void => {
+ onSelectedFolderChange(folder ? { Id: folder.Id, ManifestId: folder.ManifestId } : null);
+ setShowFolderModal(false);
+ };
+
+ /**
+ * Classes of a folder row button.
+ */
+ const buttonClass = (key: string | null, isDisabled: boolean, hasChevron: boolean): string => {
+ const base = `flex-1 px-3 py-2 text-left ${hasChevron ? 'rounded-r-md' : 'rounded-md'} flex items-center transition-colors`;
+ if (isDisabled) {
+ return `${base} bg-gray-100 dark:bg-gray-800 text-gray-400 dark:text-gray-600 cursor-not-allowed opacity-50`;
+ }
+ if (selectedKey === key) {
+ return `${base} bg-primary-50 dark:bg-primary-900/20 text-primary-700 dark:text-primary-300`;
+ }
+ return `${base} text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-700`;
+ };
+
+ /**
+ * Classes of a folder row icon.
+ */
+ const iconClass = (key: string | null, isDisabled: boolean = false): string => {
+ if (isDisabled) {
+ return 'w-5 h-5 text-gray-300 dark:text-gray-700';
+ }
+ return selectedKey === key ? 'w-5 h-5 text-primary-500' : 'w-5 h-5 text-gray-400';
+ };
+
+ const selectedFolderRow = selectedKey ? folders.find(f => folderKey(f) === selectedKey) : undefined;
+ const checkIcon = (
+ <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>
+ );
+
+ return (
+ <>
+ <div className="flex items-center gap-2 mt-2">
+ <svg className="w-4 h-4 text-gray-400 dark:text-gray-500 flex-shrink-0" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
+ <path strokeLinecap="round" strokeLinejoin="round" 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>
+ <button type="button" onClick={() => setShowFolderModal(true)} className="text-sm text-gray-500 dark:text-gray-400 hover:text-primary-600 dark:hover:text-primary-400 transition-colors">
+ {selectedFolder ? <span className="text-primary-600 dark:text-primary-400">{selectedFolderRow?.Name}</span> : <span>{t(`${tk}.NoFolder`)}</span>}
+ </button>
+ </div>
+
+ <FormModal
+ isOpen={showFolderModal}
+ title={t(`${tk}.SelectFolderTitle`)}
+ showDefaultFooter={false}
+ maxWidth="sm"
+ onClose={() => setShowFolderModal(false)}
+ icon={(
+ <svg className="h-6 w-6 text-orange-600 dark:text-orange-400" viewBox="0 0 24 24" fill="currentColor">
+ <path d="M10 4H4a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-8l-2-2z" />
+ </svg>
+ )}
+ >
+ <div className="space-y-1 max-h-64 overflow-y-auto -mx-2">
+ <button type="button" onClick={() => selectFolder(null)} className={`${buttonClass(null, false, false)} w-full`}>
+ <svg className={iconClass(null)} fill="none" stroke="currentColor" viewBox="0 0 24 24">
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M5 8h14M5 8a2 2 0 110-4h14a2 2 0 110 4M5 8v10a2 2 0 002 2h10a2 2 0 002-2V8m-9 4h4" />
+ </svg>
+ <span className="font-medium">&mdash;</span>
+ {!selectedFolder && checkIcon}
+ </button>
+
+ {flatTree.map((node) => {
+ const key = folderKey(node);
+ const isDisabled = key === excludedKey;
+ const hasChildren = node.children.length > 0;
+ const isExpanded = expandedFolderIds.has(key);
+ const count = itemCounts[key] ?? 0;
+ return (
+ <div key={key} className="flex items-stretch">
+ {hasChildren ? (
+ <button type="button" onClick={(e) => {
+ e.stopPropagation();
+ toggleExpansion(key);
+ }} className="px-2 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-l-md transition-colors flex items-center" style={{ marginLeft: `${node.depth * 1.5}rem` }}>
+ <svg className={`w-4 h-4 text-gray-500 dark:text-gray-400 transition-transform ${isExpanded ? 'rotate-90' : ''}`} fill="none" stroke="currentColor" viewBox="0 0 24 24">
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M9 5l7 7-7 7" />
+ </svg>
+ </button>
+ ) : (
+ <div className="w-8" style={{ marginLeft: `${node.depth * 1.5}rem` }}></div>
+ )}
+
+ <button type="button" onClick={() => selectFolder(node)} disabled={isDisabled} className={buttonClass(key, isDisabled, hasChildren)}>
+ <div className="flex items-center gap-3 flex-1">
+ <svg className={iconClass(key, isDisabled)} 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">{node.Name}</span>
+ {count > 0 && <span className="text-xs text-gray-400 dark:text-gray-500">({count})</span>}
+ </div>
+ {selectedKey === key && checkIcon}
+ </button>
+ </div>
+ );
+ })}
+
+ {flatTree.length === 0 && <p className="px-3 py-2 text-sm text-gray-500 dark:text-gray-400 italic">{t(`${tk}.NoFoldersAvailable`)}</p>}
+ </div>
+ </FormModal>
+ </>
+ );
+};
+
+export default FolderSelector;
diff --git a/apps/web/src/components/items/ItemIcon.tsx b/apps/web/src/components/items/ItemIcon.tsx
new file mode 100644
index 000000000..85be81cb3
--- /dev/null
+++ b/apps/web/src/components/items/ItemIcon.tsx
@@ -0,0 +1,88 @@
+import SqliteClient from '@aliasvault/client/database/SqliteClient';
+import { getAppIconSvg, ItemTypeIconSvgs } from '@aliasvault/models/icons';
+import { FieldKey, ItemTypes, LogoKinds, type Item } from '@aliasvault/models/vault';
+import React, { useState } from 'react';
+
+import type { ItemTypeIconKey } from '@aliasvault/models/icons';
+
+type ItemIconProps = {
+ item: Item;
+ altText?: string;
+ /** Tailwind size classes. */
+ sizeClass?: string;
+};
+
+/**
+ * Render an SVG string inside a sized wrapper.
+ */
+const SvgIcon: React.FC<{ svg: string; sizeClass: string }> = ({ svg, sizeClass }) => (
+ <span className={`${sizeClass} flex-shrink-0 inline-block [&>svg]:w-full [&>svg]:h-full`} dangerouslySetInnerHTML={{ __html: svg }} />
+);
+
+/**
+ * Detect the credit card brand from the card number's BIN prefix.
+ * @param cardNumber - the card number
+ */
+const detectCardBrand = (cardNumber: string | null | undefined): ItemTypeIconKey => {
+ if (!cardNumber) {
+ return 'CreditCard';
+ }
+ const cleaned = cardNumber.replace(/[\s-]/g, '');
+ if (!/^\d{4,}/.test(cleaned)) {
+ return 'CreditCard';
+ }
+ if (/^4/.test(cleaned)) {
+ return 'Visa';
+ }
+ if (/^5[1-5]/.test(cleaned) || /^2[2-7]/.test(cleaned)) {
+ return 'Mastercard';
+ }
+ if (/^3[47]/.test(cleaned)) {
+ return 'Amex';
+ }
+ if (/^6(?:011|22|4[4-9]|5)/.test(cleaned)) {
+ return 'Discover';
+ }
+ return 'CreditCard';
+};
+
+/**
+ * The icon of an item: a logo the user picked, else the favicon for logins and aliases, the card brand for
+ * credit cards, and the note icon for notes.
+ */
+const ItemIcon: React.FC<ItemIconProps> = ({ item, altText, sizeClass = 'w-10 h-10' }) => {
+ const [imageFailed, setImageFailed] = useState(false);
+
+ const chosen = item.LogoInfo && item.LogoInfo.Kind !== LogoKinds.Favicon ? item.LogoInfo : null;
+ if (chosen?.Kind === LogoKinds.Builtin) {
+ const builtinSvg = getAppIconSvg(chosen.Source);
+ if (builtinSvg) {
+ return <SvgIcon svg={builtinSvg} sizeClass={sizeClass} />;
+ }
+ }
+ if (chosen?.Kind === LogoKinds.Custom) {
+ const uploadedSrc = item.Logo ? SqliteClient.imgSrcFromBytes(item.Logo) : null;
+ if (uploadedSrc && !imageFailed) {
+ return <img src={uploadedSrc} alt={altText ?? item.Name ?? 'Item'} className={`${sizeClass} flex-shrink-0 rounded-lg`} loading="lazy" decoding="async" onError={() => setImageFailed(true)} />;
+ }
+ }
+
+ if (item.ItemType === ItemTypes.Note) {
+ return <SvgIcon svg={ItemTypeIconSvgs.Note} sizeClass={sizeClass} />;
+ }
+
+ if (item.ItemType === ItemTypes.CreditCard) {
+ const cardNumberField = item.Fields?.find(f => f.FieldKey === FieldKey.CardNumber);
+ const cardNumber = cardNumberField?.Value ? (Array.isArray(cardNumberField.Value) ? cardNumberField.Value[0] : cardNumberField.Value) : undefined;
+ return <SvgIcon svg={ItemTypeIconSvgs[detectCardBrand(cardNumber)]} sizeClass={sizeClass} />;
+ }
+
+ const logoSrc = item.Logo && !imageFailed ? SqliteClient.imgSrcFromBytes(item.Logo) : null;
+ if (logoSrc) {
+ return <img src={logoSrc} alt={altText ?? item.Name ?? 'Item'} className={`${sizeClass} flex-shrink-0 rounded-lg`} loading="lazy" decoding="async" onError={() => setImageFailed(true)} />;
+ }
+
+ return <SvgIcon svg={ItemTypeIconSvgs.Placeholder} sizeClass={sizeClass} />;
+};
+
+export default ItemIcon;
diff --git a/apps/web/src/components/items/ItemTypeSelector.tsx b/apps/web/src/components/items/ItemTypeSelector.tsx
new file mode 100644
index 000000000..61eeefda9
--- /dev/null
+++ b/apps/web/src/components/items/ItemTypeSelector.tsx
@@ -0,0 +1,95 @@
+import { type ItemType, ItemTypes } from '@aliasvault/models/vault';
+import React from 'react';
+import { useTranslation } from 'react-i18next';
+
+type ItemTypeSelectorProps = {
+ selectedType: ItemType;
+ onSelectedTypeChange: (itemType: ItemType) => void;
+ showDropdown: boolean;
+ onShowDropdownChange: (show: boolean) => void;
+};
+
+/** All item types, in menu order. */
+const ALL_TYPES: ItemType[] = [ItemTypes.Login, ItemTypes.Alias, ItemTypes.CreditCard, ItemTypes.Note];
+
+/**
+ * The icon of an item type.
+ */
+const TypeIcon: React.FC<{ itemType: ItemType }> = ({ itemType }) => {
+ switch (itemType) {
+ case ItemTypes.Login:
+ return <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M15 7a2 2 0 012 2m4 0a6 6 0 01-7.743 5.743L11 17H9v2H7v2H4a1 1 0 01-1-1v-2.586a1 1 0 01.293-.707l5.964-5.964A6 6 0 1121 9z" /></svg>;
+ case ItemTypes.Alias:
+ return <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z" /></svg>;
+ case ItemTypes.CreditCard:
+ return <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M3 10h18M7 15h1m4 0h1m-7 4h12a3 3 0 003-3V8a3 3 0 00-3-3H6a3 3 0 00-3 3v8a3 3 0 003 3z" /></svg>;
+ default:
+ return <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" /></svg>;
+ }
+};
+
+/**
+ * The translation key of an item type's name.
+ */
+const typeNameKey = (itemType: ItemType): string => {
+ switch (itemType) {
+ case ItemTypes.Login: return 'components.main.items.itemTypeSelector.TypeLogin';
+ case ItemTypes.Alias: return 'components.main.items.itemTypeSelector.TypeAlias';
+ case ItemTypes.CreditCard: return 'components.main.items.itemTypeSelector.TypeCreditCard';
+ default: return 'components.main.items.itemTypeSelector.TypeNote';
+ }
+};
+
+/**
+ * Dropdown to pick the item type.
+ */
+const ItemTypeSelector: React.FC<ItemTypeSelectorProps> = ({ selectedType, onSelectedTypeChange, showDropdown, onShowDropdownChange }) => {
+ const { t } = useTranslation();
+
+ return (
+ <div className="relative mb-4">
+ <div className="relative w-full px-4 py-3 bg-primary-50 dark:bg-primary-900/20 border border-primary-200 dark:border-primary-800 rounded-lg flex items-center gap-2">
+ <button type="button" onClick={() => onShowDropdownChange(!showDropdown)} className="peer absolute inset-0 rounded-lg" aria-label={t('sharedResources.ItemTypeLabel')}></button>
+ <div className="relative flex items-center gap-2 min-w-0 pointer-events-none peer-hover:opacity-80 transition-opacity">
+ <span className="shrink-0 text-primary-600 dark:text-primary-400"><TypeIcon itemType={selectedType} /></span>
+ <span className="text-primary-700 dark:text-primary-300 font-medium text-sm truncate">{t(typeNameKey(selectedType))}</span>
+ </div>
+ <div className="relative flex-1 flex items-center justify-end gap-1 min-w-0 pointer-events-none peer-hover:opacity-80 transition-opacity">
+ <span className="text-xs text-primary-600/80 dark:text-primary-400/80 truncate">{t('sharedResources.ItemTypeLabel')}</span>
+ <svg className={`w-4 h-4 shrink-0 text-primary-500 transition-transform ${showDropdown ? 'rotate-180' : ''}`} fill="none" stroke="currentColor" viewBox="0 0 24 24">
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M19 9l-7 7-7-7" />
+ </svg>
+ </div>
+ </div>
+
+ {showDropdown && (
+ <>
+ <div className="fixed inset-0 z-10" onClick={() => onShowDropdownChange(false)}></div>
+ <div className="absolute z-20 mt-1 w-full bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-lg shadow-lg overflow-hidden">
+ {ALL_TYPES.map((itemType) => {
+ const selected = selectedType === itemType;
+ return (
+ <button key={itemType} type="button" id={`itemTypeSelector_${itemType}`} onClick={() => {
+ if (!selected) {
+ onSelectedTypeChange(itemType);
+ }
+ onShowDropdownChange(false);
+ }} className={`w-full px-4 py-3 text-left hover:bg-gray-50 dark:hover:bg-gray-700 flex items-center gap-3 border-b border-gray-100 dark:border-gray-700 last:border-b-0 ${selected ? 'bg-primary-50 dark:bg-primary-900/20 text-primary-700 dark:text-primary-300' : 'text-gray-900 dark:text-white'}`}>
+ <span className={selected ? 'text-primary-600 dark:text-primary-400' : 'text-gray-500 dark:text-gray-400'}><TypeIcon itemType={itemType} /></span>
+ <span className="font-medium text-sm">{t(typeNameKey(itemType))}</span>
+ {selected && (
+ <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>
+ );
+ })}
+ </div>
+ </>
+ )}
+ </div>
+ );
+};
+
+export default ItemTypeSelector;